Let us set up the usual scenario. A party enters a dungeon. It then enters a room, such as I had in my simulation, finds a group of creatures, and then falls back to the doorway in order to reduce the number of possible attackers. The fighters 'hold' the doorway while the mages cast spells and the cleric keeps the fighters whole ... and when the enemy starts to dwindle, the party moves forward and mops up.
There are a couple of assumptions being made here - first and foremost being that the enemy has any reason to force their way through the door. Why shouldn't the enemy, as soon as the party retreats to the doorway, simply move to a place where the party can't see them? After all, its the party doing the invading here, not the enemy. Logically, the enemy should have their lair set up so that A) the party in the doorway is vulnerable to some trap which can be sprung at will by the enemy; and B) the party in the doorway isn't a threat until they leave their comfortable, safe doorway and venture across the prepared, open surface to where the enemy is lodged in their own defensive location.
Just look at what is typically used as a "guard room" the party would likely encounter at the front of a creature's lair:
Lot of thinking went into this one. Typically, it's all of 20' across - why would you make it bigger, it's only the forward defense for all your stuff? - so of course the enemy gets wasted. The thieves with bows and the spellcasters can see every corner of the room, and a torch can light everything, so even if the enemy does pull back to the corners they're still vulnerable. The players can assess the strength of the enemy and implement their spells/attacks accordingly.
Note that the combat simulation I provided gave a wide expanse with places to hide. This above is just a death trap ... for the defenders.
Why not this?
This isn't particularly clever. Even goblins with an 8 intelligence could have been shown how to do this by a passing stranger of potentially any race.
All right, what if it is just any door? What if the enemy does have a reason to push past the party? It happens.
Missile weapons, anyone? I might not be able to get more than two hand-to-hand attackers in the space the doorway provides, but I bet I can fit quite a number of thrown missile weapons into it. I recognize that often humanoids don't have missile weapons ... at least according to the books. I didn't give the goblins in my simulation missile weapons - but I could have very cheaply.
What if, throughout my lair, I pile up small cairns of fist-sized stones? As the party moves through the rather empty dungeon area, these piles are everywhere. Being stones, they're not convenient to collect or otherwise remove, and even if the piles are broken apart, what matter? When the enemies find the party, there should be more than enough missiles around. A fist sized stone may not travel very far, it may not do the damage of a long bow, but I'll bet the party runs out of arrows before my fifty or a hundred kobalds run out of rocks.
And if we're fighting something a bit brighter than kobalds and goblins, how about a little lamp oil, hm? Doorways are nice, cramped spaces, excellent for fire attacks ... lots and lots of splash damage. And just how long is that fighter going to hold the doorway when he's suddenly covered in burning oil? 2-12 damage may not be much, but it isn't the sort of thing you can just ignore and go on fighting. It is the sort of thing you react to by breaking ranks, falling to the ground and quickly rushing to put the fire out - and needing aid. Gee, that doorway doesn't seem like such a good defense any more.
It takes a fair while (in combat terms) to prepare a new burning flask of oil (even if you have the flame and the flask ready), so there's time to run, slam the door ... or rush the room. The last thing you want to do is stand passively in the doorway until the oil is thrown.
Incidentally, I haven't ever found any real military tactical manual, ever, which has a chapter on the benefits of fighting in doorways. If someone wants to send me a link, I'll have a look at it. I'm guessing this is just a long standing D&D canard that has somehow gained the status of being tactically brilliant because its hard to believe a goblin can throw a rock.