In the same way that fish and other sea creatures move through a medium of water, we humans and other land creatures move through a medium of air. We derive our life mainly from the opposite element, earth: we grow crops, and live off those crops or animals who eat those crops.
So too do sea creatures derive their life ultimately from the opposite element of water, fire - by spontaneously generating due to the action of the sun, or by living off creatures who do.
Thus it is only logical that in a medium of earth, life should derive mainly from the opposite element, air. In other words, the creatures of the world under the surface are creatures of air - what we call caverns, caves, and so on.
Dungeons are rare and massive creatures of air - the equivalent of whales or elephants. Just as there may be hundreds of times more dogs than elephants, and hundreds of times more ants than dogs, so too we find air pockets and fissures more common than caves, and dungeons the rarest of all. Like all massive creatures dungeons are predators, taking the earth they require to live in the form of humans and other creatures.
However, they move far more slowly than ourselves, since they are a weak element (air) moving in a resistant one (earth), where we are the opposite. They are far too slow to catch creatures of earth, and can't pursue us into their natural element any more than a fisherman can dive into the deepest sea to catch a fish.
Thus, like a fisherman, they present lures to attract creatures of earth - the treasure and magic items which are to be found there.
Once we get there they may catch us by their own action: cave-ins for example. But, again, they find it as difficult to move the earth as we find it easy to move the air.
Ingeniously, they have developed an understanding with other creatures of earth. Much like a hunter who may tame a dog, and use it to catch wolves, keeping the loyalty of the dog by sharing the meat, so too dungeons have an understanding with the creatures who live there: help me kill the creatures who come, and you may take enough of them to live. And, like a dog kept safe in the house from those same wolves, so too monsters are safe in their dungeons from the humans who would otherwise hunt and destroy them.
However the partnership between dungeons and their monsters is even more intimate, more akin to that between bees and flowers. Monsters are the means by which dungeons reproduce. When a dungeon contains too many monsters for it to support, it disgorges some of them into the surface world, where they travel briefly (as briefly as they can, since they are vulnerable on the surface) until they can find a place to grow another dungeon.
It has been frequently noted that dungeons appear to make no sense.
On the surface world anyone can labour, but only a few can use magic. Dungeons, being creatures of air rather than earth, are in the opposite situation. It would be a remarkable feat for a gust of air to move a boulder - but all dungeons are magical.
This explains many otherwise inexplicable features of dungeons. For example, that mutually hostile creatures can live next door to each other without one exterminating the other; that there can be a shop in the middle of a dungeon; that creatures with no need for treasure can still carry it - indeed that creatures without any means of carrying treasure can have it on them.
It finally explains the apparently illogical layout of dungeons. In fact, dungeons are generally laid out as magical runes, which spell out a series of relevant phrases in a magical language: 'let wolves have treasure on them', 'let the traps re-set themselves' and so on.
Adventurers are, to the dungeon, like microbes to the human body - either too little or too many can be unhealthy. Thus many dungeons have evolved means to regulate the numbers. For example some dungeons will have a bouncer out the front - a large goblin, rock golem, or similar creature who, if the dungeon is 'full', will allow new adventurers in only when some already in the dungeon die. Sometimes the bouncers will apply arbitrary rules as to who to let in (saying, for example, "sorry mate, ladies only tonight. Oi - not in that armour. You're a halfling are you? Got any ID?").
Other dungeons will employ a turnstile, or a ticketing system. Yet others will have magic entrances, which can only be crossed at particular times.
Dungeons will also generally have means to achieve the opposite end, of attracting adventurers when there aren't enough. For example they may send out hostile creatures to attract heroes to deal with them. Others will pile up small amounts of treasure by their entrance, hoping to advertise that greater treasure lies within.
Of course, not everywhere in the underworld is a dungeon - not even every arbitrary collection of traps, monsters and treasure. Some such appear to have been set up as psychological experiments by beings unknown, with adventurers as the 'rats' and treasure as 'cheese'.