Same thing happens if you recall people and are standing too close to a wall or door, or tele ring right onto the exact spot of a door, the game tries to place the player/pet exactly where it should be, or as close as possible, if there is no suitable space then it sends it randomly anywhere on the map.
Most people will have experienced this with being recalled and players get scattered. On large maps the pets usually end up a long way from you and will very quickly tele back to you like they do if you have just taken them off rest, so it's not a problem, on smaller maps as you correctly pointed out they are likely to be too close to you to prompt a teleport.
The answer to this is to either rest them before you walk in and walk to a suitable spot before recalling them, or in most cases you are ok just to run in the door because you are clear of the door and there's enough space for the pets by the time they have teleported to you.
It's a very simple solution which, while being a little annoying sometimes if you forget, is only really fixed by quite a large and complicated procedure in how the server determines where a player or pet is to land, the significant GM time required to do that is far better spent on new content and maps for us to enjoy.