Four years back I did a series called "Monster Ecology," where I made some die-roll tables for a monster's origin, eating habits, and reproduction.
You can find the wrap-up post and all of the previous ones in this link:
Pulling it All Together
I already did origins. But here is another table, which can answer the more specific question - how did this monster get here? As in, in this dungeon, in this room, in this specific keyed area on the map.
1) Summoned - the monster was summoned to this area. It may be originally a summonable create, from another dimension or world. Or it may be a perfect normal, mundane creature (such as they are) that was brought by magic.
For example: elementals or demons could be summoned by the appropriate spells. An animal brought by a druid's call. A monster gated in from another dimension thanks to some strange portal (which may or may not be here, now - this could just be the end point.)
2) Spawned - literally born here. This is commonly for creatures which reproduce. It was born, hatched, spawned, extruded, or otherwise reproduced from its parent. It might even have been cloned or grown from a split-off part. However, and alternate explanation is likely if you go back far enough - how did its parents get here? Roll again to determine that.
3) Wandered - it got here just like the delvers probably did. It wandered in from elsewhere. It might be in transition to somewhere else (1-2) or here to stay (3-6). In any case, it came seeking shelter, food, loot, something of mystical or religious significance, escaping something, came for work, or any of a myriad of reasons to enter the dungeon. Most likely are food, shelter, or loot, but this is a good chance to tie in to a larger significance of the dungeon. Or to tie the dungeon to another location - if this creature came here to escape a foe at a prior location, perhaps there is a clue to that location. It may have been forced to leave loot behind. Not all maps are to treasure, sometimes they lead back home!
4) Brought - some external power brought the creature with it. Delvers bringing a pet, other creatures bringing pets or guards, etc. or it might have once been a junior delver itself. Orcs may have brought their wolf-dogs with them then abandoned them (or were themselves slain). An owlbear infested with red death beetle grubs might have died and spawned all of those red death beetles. The creature did not come alone, or fully of its own accord. It might like or here or be hoping to leave at some point, or just mindlessly going about its business as if it never left. Creatures placed as guards count as "brought," too, especially if it's not really their decision to be guarding the stairwell in room 4, level 2, instead of being off doing something more interesting.
5) Created - the creature was created on the spot. Created with magic, built from steam engine bits and spare parts, assembled out of clockwork, piled up and given life with an old silk hat they'd found, etc. The creature may know no other life or experience.*
This is generally tied to a construct-like origin, but it's possible that super-science or magictech clone tanks, force of a wizard's will, or evil darkness that spawns bugbears and hobgoblins of the mind into literal bugbears and hobgoblins will also do this. Magic is usually involved, especially critical spell failures (the origin for several of these creatures) or other "use error." Fountains or gates that spew monsters may be summoning them (see #1) or creating them.
6) It's Not Here - tied mostly to special rooms, but the monster isn't there at all. It's elsewhere, and you temporarily go there to deal with it. Usually this is tied to a way back (teleport to the weird space, fight the monster - winner goes home, loser is devoured) or a way forward (teleport to the weird space, fight the monster, winner proceeds, loser is bounced back to start again). In any case, the monster is not actually in the place. More mundanely, this result could mean it's not here now, but it will be back in the future - in a few minutes, in a few days, in a few thousand years, whatever.
As always, you can roll on this table or just pick. I'd just pick, otherwise 1 in 6 monsters are part of a special magical area, 1 in 6 are created, etc. and you've gone beyond funhouse and gonzo into just mathematical weirdness and nonsensical combinations. For a monster you just can't decide on ("How did that otyugh get here, it couldn't have operated the puzzle door or climbed that ladder!") rolling can be a great creative spur.
* And if you don't accidentally scare it with fire, it might stay for espresso.