When a spell is cast targeting a creature, legality of targets is checked twice: once when the spell is cast (to ensure it's a valid target), and again when the spell resolves (CR 608.2b). If a target is no longer legal at resolution time, the spell fails to resolve.
Hexproof means the creature "can't be the target of spells or abilities your opponents control" (CR 702.11b). If the controller of the creature responds to the spell by giving it hexproof — via a card like Dive Down or Heroic Intervention — then by the time the original spell tries to resolve, the creature is no longer a legal target for that opponent's spell.
Under CR 608.2b, if all targets of a spell have become illegal by the time it would resolve, the spell is countered by the game rules. It is removed from the stack with no effect, and its controller doesn't get to choose new targets.
Concrete example: Your opponent attacks and casts Lightning Bolt targeting your Grizzly Bears. You respond by casting Dive Down on your Bears, giving them hexproof. When Lightning Bolt tries to resolve, the Bears are no longer a legal target (hexproof prevents them from being targeted by your opponent's spells). Lightning Bolt is countered by game rules and does nothing.
Note: if a spell has multiple targets and only some become illegal, the spell still resolves but does nothing to the illegal targets (CR 608.2b). But if the creature was the only target, the spell fizzles entirely.
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.