Why does the Will-o'-Wisp have immunity to magic, and especially why are these two spells the ones to bypass it? Nothing in either the stat sheet or the lore of the WoW suggests the reason. And that's because there is no reason except that the WoW is plagued by its heritage from previous editions.
Spoiler: The original will-o'-wisp, and special relativity
Show
You see, in 1st and 2nd editions, the WoW was very different from what it has become. It was not a standalone monster, but the adult form of another monster, some small humanoid shapeshifter Fey called a boggart. The boggart could shapeshift into any humanoid of its size, but also in an incorporeal ball of light with no physical substance: the will-o'-wisp (and here is the second big difference between 1st and 3rd edition will-o'-wisps, in 1st edition, WoW were completely incorporeal, with no real body, only some concentrated, sentient light). As they matured, they spent more and more time in will-o'-wisp form until they couldn't go back to being a boggart anymore. Yes, you heard that right, a corporeal being that could shapeshift into an incorporeal one. That is already quite strange, but what is most unique is that Gary Gygax actually considered real-world physics in this transformation. Indeed, E=mc², and destroying mass liberates incredible amounts of energy, while creating mass consumes the same amount. When the boggart changed into a will-o'-wisp, the air in the vicinity heated up so much that anyone there took 1d6 damage. But this energy is far from what would be liberated by the body of a small humanoid completely vanishing (as a reminder, the strongest man-made explosion ever, the Tsar Bomba, who could obliterate any metropolis and kill everybody in a 40 miles radius represented no more than 3 kg of consumed matter). The vast majority of it was channeled through the will-o'-wisp into the Negative Energy Plane, then retrieved when the will-o'-wisp took a physical form again.
Spoiler: The will-o'-wisp's weaknesses, and quantum physics
Show
It's this connection with the Negative Energy Plane that gave the will-o'-wisp magic immunity. Any magic that could affect it was just channeled to the Negative Plane and lost. The exceptions were Magic Missile and Maze. The explanation was that magic missile somehow disrupted the lattice of information of the will-o'-wisp itself (Magic Missile never misses, even if the target doesn't really exist), and hence could damage it, while Maze blocks the pipeline to the Negative Plane but my headcanon is that a monster with a name starting with two W's can't handle so many M's in a spell's name.
But another thing that could disrupt this link was simply physical weapon attacks. You see, will-o'-wisps in 1e were just a ball of information with no physical form, even the light was just some energy leaking through its link with the Negative Energy Plane, which is why it's invisible when turning the light off, there really is nothing to see (also why it couldn't sustain its invisibility permanently at the time). However, hitting it with physical matter could "possibly" disrupt it. The event is described as completely random and unlikely even if you strike the light of the will-o'-wisp, as if the light was only the probability of presence of the "damageable" part of the will-o'-wisp. That really reminds me of wavefunctions in quantum physics and how interfering lasers can create physical matter for an instant in a completely random manner. This randomness translates into the ludicrous AC bonus that later became the Deflection bonus we see in 3e.
Spoiler: When WotC gives up on trying to understand their own monster
Show
So, at this point, the will-o'-wisp was two intricately linked monsters with weaknesses that only made a little sense when factoring multi-Plane theory and real-life advanced physics. On top of it, one of the two was an incorporeal one that could be still hurt by physical nonmagical weapons and could turn invisible and be seen by See Invisibility, but with no physical form to really see. That was way too much for the clear, well-defined edition they wanted for 3e.
But the thing is, they seemingly liked the will-o'-wisp. I don't know how that happened, if one of the devs already had a campaign ready with some will-o'-wisps as a major enemy, or if they considered that it was one of the most iconic monsters in the game, but they decided not to cut it from 3e, and even to keep its stat sheet almost exactly identical to what it was. However, to keep it from being as complicated as before, they just removed every instance and reference of the boggart, of the Negative Energy Plane and of that weird randomness that prevented it to be hurt most of the time, and changed every last bit of its lore to create something completely different, but with the same final result.
Spoiler: How WotC wants the same monster, but different, but still same
Show
It can be hit by physical weapons? Then make it not incorporeal at all, and call it a day.
It can channel energy into lightning attacks? Let's say that it's because of a chemical reaction when it eats swamp gases.
It evolved out of a sadistic fey that hates humans? Ah no, no more fey! Nothing from before, except the stats. Let's make it instead an aberration which feeds on the chemicals produced by humanoids when they experience fear and pain. I don't care if that doesn't make sense! Make it not magical at all, I don't want anything complicated on this monster anymore!
It shines and can extinguish its glow to be invisible? Now it's because it exhales flamable gases that ignite when in contact with oxygen, and it can just hold its breath. Plus it's naturally transparent because... It's gas itself! Give it the Air subtype!
It has incredible AC? I said now it has the Air subtype, make it deflection bonus or something due to it exhaling gas that repel weapons.
How can an air aberration be so intelligent, even more than an humanoid? Make it some sorte of cluster of smaller sentient gas bubbles that can think together as a hive mind (I'm absolutely not kidding, that's what the will-o'-wisp is in 3.X)
And finally, it has immunity to all magic except Maze and Magic Missile! ..... There's no mundane way to explain that, is there? Just put a "nobody really knows why" and everything will be fine.
And that's how WotC changed everything, but kept all the abilities, and made the monster even more incomprehensible by having the magic immunity, the almost absent strength and the deflection bonus to AC not be explained at all. Truly the best way they could have went.
Spoiler: What about after 3rd edition
Show
A few years later, 4th edition came up, and once again, the devs were self-conscious that the will-o'-wisp made no sense, maybe even less so than in 2nd edition. So they decided to come back. It's a Fey again, with a lot of clearly magical light abilities. I can only assume this is the same will-o'-wisp as it 1st edition, but since this is 4th edition, who cares about iconic abilities, or just interesting ones? Immunity to magic just doesn't exist, and they don't have particularly good AC either, so no need to explain anything, and you can have fun just hitting the thing with a stick... *sigh* 4e never fails to disappoint.
5e wasn't much better. This edition brought back a lot of interesting abilities, and gave much more thought to the lore. But once again, doing that for the Fey will-o'-wisp would be way too complicated. So they changed it again. Not a Fey, not an Aberration, now it's an Undead! The spirit of criminals killed in a swamp. At least they didn't want to keep the same stats from before. That makes the 5e will-o'-wisp just a completely different creature from before. And honestly, that's probably the best course of action on their part.
So, in its existence, the lore of the will-o'-wisp changed so utterly that even its creature type was different, not once, but
three times! And the 3rd edition one was probably the worst iteration of that, with some endeavor to keep nonsensical abilities while not explaining the majority of them within the new lore. That's why I consider the WoW the most confusing monster in all of D&D, it's the combination of every single worst design decisions WotC could have made, from the very beginning of D&D to the modern era.