it's a very stupid Legendary who willingly remains in combat with an adventuring party on their terms, without any backup.
Purple Worms might well be very stupid. They also lack magic resistance. Same for Dragon Turtles and Kraken?
Meanwhile, yes, if you run a dragon etc. as a videogame boss monster, that's very different from running it as an NPC who might have an interest in survival and act accordingly.
And on a third hand, then the legendary NPC might also have goals for which they're willing to risk a fight to the death. If they've spend the last century on their Master Plan for World Domination, and the "meddling kid" PCs show up at the critical moment, then the Legendary villain might stay in combat, hoping to keep the PCs from destroying his megadracolich that's within 1 hour of activation, rather than abandon that century's worth of effort. (If the spell to create the megadracolich requires 8 hours of Concentration, and he's already spent 7 hours on it, and breaking concentration means spell failure AND component loss... then the Big Bad might even try to fight the PCs while maintaining Concentration.)