This happens when your pet house is placed in such a position that your pet doesn’t have enough room to spawn.
When this happens, the game will find the closest available space to spawn the pet, which might be an area not visible to you.
In order to see your pet, the pet house should be moved to a location with space available next to it, so that the pet can spawn there.