There are some tricks a game master can employ in order to discourage this behavior. Locking the player characters in the dungeon (whether literally or by simply denying them egress through having them get lost, having monsters block the exit, etc.), disrupting spell-casters' rest with random encounters, etc. But it's very easy to overdo these sorts of things, however, and can begin to smack of "the DM is just going to punish us for leaving, so we might as well keep going until we're dead" in the minds of the players.
I wonder, though, if there is some way of addressing this issue in a way that doesn't offend my grognardly sensibilities? On the one hand, part of the whole aesthetic of an old-school game is resource management. It's not just about making the right tactical choices in a combat, but making the right operational choices when selecting spells and buying equipment. In once sense, the megadungeon is its own solution to the problem; if the game master doesn't slack off when it comes to rolling for random encounters, the mere fact that the player characters may well need to fight their way out will encourage them to stay in longer. But that just shifts the site of rest to a barricaded room inside the dungeon, rather than the local inn or convenient cave near the site of the dungeon.
There is one solution to the problem, which applies perhaps more to the megadungeon environment than a smaller encounter area, but I'm sure the principle could be applied.
The monsters get tougher (or, perhaps, more wary) if the player characters keep coming in and doing hit-and-run sortees.
Naturally, this doesn't mean that resistance can't stiffen during the player characters' foray. Just because they haven't returned to the surface doesn't mean that the orcs will automatically stay in their rooms, conveniently grouped in 3's and 4's, perfect for slaughter and easy x.p. But that should be a more "ad hoc" thing on the part of the defenders (except for those very lawful humanoid tribes that have contingency plans already in place, complete with pole-arm-wielding troops to command narrow corridors and such), and to be expected. The idea is that pressing on should be the preferable option to retreat, except when the resources of the party really are exhausted, and R&R becomes required.