I dont know if is because a game limitation or what but seems ilogic that mobs load before walls making them scape and make unconfortable situations. Working in that way, makes walls and other structures less useful since they are not doing their job
as example i will let this screenshot that shows how a merm king tries to come back to his throne because he always can scape his cage to fight the spider from the spider farm near (near but dont even close imo) of his throne. I always need to kill him in order to have a king