OK, this is complicated. First, a few things to remember:
The show has not been perfectly consistent on magic, after all it is magic.
We learned that the wand's battery feeds the millhorse so keep it charged or they die.
We also learned that the whispering spell kills them, but a replacement may show up if one is available (Vincenzo, Star's 2nd millhorse).
Recall also that Star used the whispering spell on Ludo's hand in order to enter the realm of magic which at the time was corrupted by Toffee. Almost all the magic in the realm was inert, but Star used the last drop (that was in Glossaryck's soup) to create a new millhorse (Firstborn).
Upon creating the new millhorse, the inert magic was revitalized and wand reactivated.
Now, these events beg the question, what millhorse is powering Star's wand at that point? A millhorse soul was seen leaving Ludo's hand after the whispering spell, but Vincenzo was inside Star's wand, so what gives? Well, this isn't really spelled out, but Star's wand was "cleaved" into 2 but still connected somehow. If the millhorse lives within a pocket dimension that could be accessed by either wand, then it makes sense that Vincenzo would be killed by the whispering spell cast on Ludo's hand. And, if this pocket dimension is linked to, or possibly IS the realm of magic, then it makes sense that Firstborn could live in the realm of magic and still power her wand.
Now... as for Janna's millhorse. Firstborn did not see Janna place it under her hat, and was probably too busy to notice when teleporting them out of the realm of magic, chances are it stayed with Janna. But finally the big question, how could it survive when all magic was destroyed? Well, proximity matters here. Millhorses generate magic, they aren't like normal spell constructs. They don't need the realm of magic, on the contrary, the realm needs them. If Janna's millhorse was not in the realm of magic, it survived.
PS don't forget how Glossaryck made the first wand.