These are actually two different scenarios. A spell that never had any targets — such as a sweeper like Wrath of God — simply resolves as normal, because there are no targets to become illegal. The concept of targets becoming illegal is irrelevant to it.
A spell that originally had targets but has had all of them become illegal by the time it would resolve is countered by the rules of the game. Per CR 608.2b, if all targets of a spell are illegal when it tries to resolve, the spell is countered and has no effect. It goes to the graveyard without resolving.
If a spell had multiple targets and only some become illegal, it still resolves. It simply does nothing to the illegal targets and affects only the remaining legal ones, as much as possible (CR 608.2b).
Example: Your opponent casts Doom Blade targeting your creature. In response, you give your creature hexproof. When Doom Blade tries to resolve, its only target is now illegal. The spell is countered by the rules — your creature survives and Doom Blade goes to the graveyard with no effect.
So to directly answer: a spell with no targets at all always resolves; a spell whose every single target has become illegal is countered and does nothing.
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.