Hey Akiro,
I had the same issue with some of the bots I wrote for myself. The problem is, when your team wipes, you will be resurrected at a shrine, but at the same time the Moving-coordinates stay the same as before. Thus, the bot tries to take the shortest route from the ressurection shrine to your last called coordinates. If those coordinates are too far away from your current position, the bot gets stuck in a wall.
I solved this issue by adding a function, which discoveres, if my team wiped. So bascially, when my team died the bot will skip all other commands and returns to town. To make sure the bots doesnt get stuck in a loop when I'm dead, I added a variable %Deadontherun in front of every codeline. I had the issue, that if my team died, the bot realized I was dead, but the code got locked inside a combat loop. Then I was resurrected at a shrine, before the traveltoutpost codeline was reached. Thus, I got stuck.
This may sound cryptic right now but if you take a look at the Pongmei Chest run bot I posted at page 62 in this thread, you will see what I mean by the %Deadontherun variable.
But be aware that I wrote this function in the way, that the bot will go back to the outpost as soon as the player dies. So you either leave this function as it is and remove all resurrection skills from your heros, or you should change the function in a way, that it realizes if a certain number of heros are dead, and it sends you back (easy way) or in a way that the bot realizes that every hero with resurrection skills is dead (hard way)
I hope this helped a bit. (I didn't take a look at your code but I'm pretty sure that I had the same problem)
GL