When a spell is cast, it targets a creature at the time of casting. However, legality of targets is checked again when the spell is about to resolve (CR 608.2b). If a target is no longer legal at that point, the spell cannot resolve against it.
Protection from a color (CR 702.16) means the protected permanent cannot be the target of spells or abilities of that color. If the creature gains protection from the spell's color in response — say, via an instant like Feat of Resistance — the target is now illegal when the spell tries to resolve.
Under CR 608.2b, if all targets of a spell are illegal when it tries to resolve, the spell is countered by the rules (sometimes called 'fizzling'). The spell does nothing and goes to the graveyard without producing any effect.
Example: Your opponent casts Lightning Bolt (a red instant) targeting your 2/2 creature. In response, you cast Feat of Resistance, giving your creature protection from red. When Lightning Bolt tries to resolve, its only target is now protected from red and therefore illegal. The Bolt is countered by the rules and deals no damage.
Note: If a spell has multiple targets and at least one target is still legal, the spell resolves but only affects the remaining legal targets (CR 608.2b). But with a single-target spell like Lightning Bolt, gaining protection fully negates it.
Unofficial fan resource — not affiliated with or endorsed by Wizards of the Coast. Answers are AI-generated estimates grounded in the Comprehensive Rules and are not a substitute for an official judge. Verify anything match-critical.