You're seeing one of the classic military ideas play out in your game — control of chokepoints. As many other people have pointed out, the advantage to controlling a chokepoint is that you can step back and force the enemy to push a narrow front of combatants against a broad base of defenders — so the person coming through the door is taking the most attacks.
Obviously, though players (somewhat) tend to be better disciplined than most people were in real life — players are not going to rush their characters through pushed on by adrenaline and machoism to face multiple attackers, but probably back off and attempt to attack at range. This is assuming NPCs with little planning or expectation to be fighting indoors — but if they are? The game changes drastically.
Buying Time
NPCs fighting defensively are often buying time until reinforcements can be summoned. This means they can focus on defense, since their goal is to stay alive and keep the enemy occupied until help arrives. This may also involve using some kind of push or shove action to push the enemy back and slam the door shut. Or, maybe tripping and knocking down the enemy so their allies have to step over them to get to you.
Alternatively, they may choose to retreat from the door, throw down caltrops, or knock over an urn of burning coals, etc. and retreat to the next defensible doorway or position. Knocking over furniture to block the path might also be a worthwhile choice.
If they've already notified the reinforcements, there may be a hidden ambush in the next room, or a lot of crossbow wielders all basically waiting to see what non-ally tries to get through the door.
Or, if there's a way for the reinforcements to loop around the party's rear, they may do that, instead.
Pulling out the Wounded
You have a line of combatants. Behind them, are their replacements. When someone is wounded, an ally pulls them back and shoves them to the rear, while another person steps up and fills the gap. This requires well trained troops used to formation fighting, although, by usual D&D mythos, hobgoblins are pretty organized fighting units, so this would make sense.
Although in D&D there's no real wounding or ability loss until one hits 0 hitpoints, it might be worth remembering any surviving hobgoblins can report back intel on the group, and they can plan better — who are the spell casters? What kind of fighting styles does the group use? This is even more important when you realize that the enemies will start bringing countermeasures in tactics and defensive tools to help deal with the enemy.
Indoor Weapons
Spears are not universally good indoors, but they can make controlling a hallway or doorway a very viable option. In real life, you can get many spears lined up, two or even more lines of troops aimed in a small space. If you're using the grid rules in 5E that is more limited than real life options, but still doable.
Darts and crossbows are pretty great indoor weapons for ranged options. Short bows might also work too.
Defensive Architecture
A lot of castles throughout history had arrow slits — small openings in the walls so archers could shoot through at intruders. These mostly lined the entranceways near gates, though dungeons might have them in other places. Of course there's gates that fall shut, barred doorways and a lot of options along those lines.
There might be areas with traps that can be activated by levers or pressure plates, and the bad guys will try to steer the characters into them, or at least, use the threat of these things to slow them down and keep them at bay.
Magic and unusual options
D&D being D&D, there's a lot more options beyond what you get in real life. There's obvious spells to create webs, walls, or lock doorways, but there's a lot of other ways magic can become very tricky.
- Summoning a swarm of bugs or rats to crawl (over, around) the party in the doorway, and attack or at least disrupt spellcasters.
- Using darkness, or an illusion to make it look like the enemy still threatens — while they've actually retreated from the doorway and are making their way to somewhere safer.
- Grease spells on stairs, or narrow walkways.
- Illusions of floor hiding pitfalls, making closed doors look like blank wall space, etc.