This is a very old bug which Mojang should have fixed many years ago; there are even fixes given on the bug report (which I've taken for my own use, and they do work):
Here is a dramatic demonstration of how bad this bug can be and how effective the fixes are; I modified chicken eggs so they produced chicks that grew up in 50 ticks (2.5 seconds), since when baby mobs grow up their bounding box increases in size, greatly increasing the chance they will clip into a block:
Vanilla:
Fixed:
Note that when fixed zero chickens escaped, even after spawning hundreds into a 3x3 pen; they also don't escape after reloading the chunk they are in (in singleplayer they can also phase through fences without growing up or reloading chunks since the client and server access the same "BlockFence" instance, including fields that specify the block bounds, which depend on their state). Likewise, when growing up next to a wall they only took a single hit of damage before being pushed out (which I fixed by giving them one tick of immunity from suffocation damage when growing up).
title.
never happened to me but my animals do it when there all together,
Join in the Chaos
This is a very old bug which Mojang should have fixed many years ago; there are even fixes given on the bug report (which I've taken for my own use, and they do work):
MC-2025 Mobs going out of fenced areas/suffocate in blocks when loading chunks (check out the number of votes and duplicates, they don't even give so much as a "postponed" resolution, and the "fix" version listed was simply based on somebody claiming they couldn't reproduce it)
Here is a dramatic demonstration of how bad this bug can be and how effective the fixes are; I modified chicken eggs so they produced chicks that grew up in 50 ticks (2.5 seconds), since when baby mobs grow up their bounding box increases in size, greatly increasing the chance they will clip into a block:
Fixed:
Note that when fixed zero chickens escaped, even after spawning hundreds into a 3x3 pen; they also don't escape after reloading the chunk they are in (in singleplayer they can also phase through fences without growing up or reloading chunks since the client and server access the same "BlockFence" instance, including fields that specify the block bounds, which depend on their state). Likewise, when growing up next to a wall they only took a single hit of damage before being pushed out (which I fixed by giving them one tick of immunity from suffocation damage when growing up).
TheMasterCaver's First World - possibly the most caved-out world in Minecraft history - includes world download.
TheMasterCaver's World - my own version of Minecraft largely based on my views of how the game should have evolved since 1.6.4.
Why do I still play in 1.6.4?
Hmm..weird. I’ve seen animals being a bit peculiar, but I’ve never seen a villager do that.
~Doctor Daylight~
If you've had villagers disappearing from your iron farm pods, you've probably seen this bug.