What happens is that there is only one grid that you play on, and when you enter a dungeon the grid just changes itself so that it looks different. Basically when you enter/exit the dungeon you don’t actually go anywhere it just looks like you do.
So when you exit the dungeon you are always going to enter the overworld screen from the top. Since you are effectively in both the overworld and dungeon at the same time the game thinks you entered that specific room of the dungeon from the top, realizes the door is somehow closed and resolves the issue by opening the door for you.
Basically just enter the dungeon, immediately leave the dungeon, and immediately enter the dungeon again and it should work.