When a spell is cast, its targets are chosen and locked in. However, legality of those targets is checked again as the spell begins to resolve. This is governed by CR 608.2b: if all of a spell's targets are illegal at that point, the spell is countered by the game rules and does not resolve — it simply goes to the graveyard with no effect.
Hexproof (CR 702.11) means the permanent or player cannot be the target of spells or abilities controlled by opponents. If a creature gains hexproof after a spell targeting it has been cast but before that spell resolves, the creature is now an illegal target for the spell. Since the target became illegal, the spell cannot affect it.
This is different from shroud or protection — but the outcome for targeting is the same. The key window is the time between casting and resolution (i.e., while the spell is on the stack). If the target gains hexproof during that window, the spell will fizzle when it tries to resolve.
Concrete example: Your opponent casts Lightning Bolt targeting your Grizzly Bears. In response, you cast Ranger's Guile, giving Grizzly Bears hexproof until end of turn. When Lightning Bolt tries to resolve, Grizzly Bears is an illegal target. Lightning Bolt is countered by the game rules (CR 608.2b) and goes to the graveyard — Grizzly Bears takes no damage.
Note: if a spell has multiple targets and only some become illegal, the spell still resolves but only affects the remaining legal targets (CR 608.2b). It only fully fizzles when all targets are illegal.
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.