With the glut of chinese, japanese, and korean light novels and comics being translated these days, more and more stories about main characters who get reincarnated as a dungeon or are otherwise somehow put in charge of one have become more common.
Turns out you can actually replicate this in D&D pretty much using straight canon and very minor tweaking.
Per the DMG section on Intelligent items: "intelligent items are treated as constructs"
Per the table in the same section: gives various costs to enchant an item with intelligence.
Per the Stronghold Builder's Guidebook: a stronghold space is a unit of measurement of a cottage, tower, castle, keep, dungeon, and more, approximately 20'x20'x10'.
Per the SBG on Wondrous Architecture: an item which can take up (fountain, statue, etc) or even be an entire stronghold space (a closet or room or even a hall).
Per the SBG if you want an magical effect to take up more than one space (for really big rooms, halls, or even the entire structure) you simply pay the listed cost for the effect times the number of spaces you want the effect to affect.
Ergo, you can enchant rooms to be intelligent.
Ergo, you can enchant your entire dungeon to be intelligent.
Ergo, once your room and/or dungeon is intelligent, it is now officially a construct.
Per the MM1 and Savage Species, creatures need to have an INT of 3 or more in order to take class levels instead of HD when advancing.
Per the MM1 and Savage Species creatures can take either HD for advancement, or levels for advancement, and according to the SS, you can also take templates for advancement when leveling up.
So not only is your dungeon an intelligent construct, it can take levels, gain construct HD, gain feats (leadership for minions, landlord for bonus funds every level to expand), gain skills, and of course, summon monsters and manifest powers. (or spells, if you really insist... sigh.)
I suggest levels in Spell to Power Erudite, Dungeon Lord, and maybe psi-Artificer.
It's not so much that this concept itself is inherently broken, but rather, once you've gotten this far, it becomes a foundation whereupon the potential for seriously advanced breakage becomes swiftly apparent.
In any case, I think I know where my next bag of devouring is going to lead to....