From the Super Mario Wiki
The Magnifying Glass is an item used for finding Red Coins in Super Mario World 2: Yoshi's Island and its remake Yoshi's Island: Super Mario Advance 3. Magnifying Glasses can be found in any of the Bonus Challenge games and when used, its effects continue until a Yoshi reaches the end of a level or death. The Magnifying Glass detects Red Coins that are disguised as Gold Coins and turns them red and visible to the Yoshi so he may more easily collect all twenty Red Coins in the level.
In Paper Mario: Sticker Star, the Magnifying Glass is a thing first found in the Sandshifter Ruins. It can also be bought from a Toad in Decalburg. In battle, the magnifying glass intensefies the suns rays on the enemy, causing burn damage.