why can foxy see through the mask

Foxy can see through the mask in Five Nights at Freddy’s 2 because, in the game’s mechanics and most popular lore theories, he simply does not use the same “facial recognition” behavior as the other animatronics and is coded to always treat you as a human intruder, mask or not.
Quick Scoop
In FNAF 2, the Freddy mask works on most animatronics because they rely on facial-recognition style logic: if they detect a Freddy head where a human face should be, they back off, thinking you are just another animatronic. Foxy is an exception and is usually handled with the flashlight instead of the mask, which is why experienced players focus on flashing the hall rather than putting the mask on when Foxy appears.
In‑universe lore theories
Fans often explain Foxy’s behavior by saying his recognition systems are damaged or different, so he cannot be fooled by a simple headpiece. Some theories add that Foxy may have “learned” to tell a person in a costume from a real animatronic after witnessing a disguised killer, which is why he identifies you as a human in a mask and still attacks.
Game design angle
A widely accepted view is that this is also a deliberate game design choice to keep gameplay tense and varied. If the mask worked on every animatronic, players could rely on a single safe tactic; Foxy ignoring the mask forces you to juggle both the mask and flashlight, increasing difficulty and suspense.
TL;DR: Foxy can see through the mask because his behavior is programmed to ignore it, and most fan theories say his optics or experience let him recognize you as a human in a fake head, not a real animatronic.
Information gathered from public forums or data available on the internet and portrayed here.