this seems to happen when you have a lot of them in the same fenced of area. this applies to both fences and stone walls
To reproduce:
1. Create fenced off area
2. Fill it with farm animals, then wait a few minutes and they will be outside. best way to see this is dye sheep pink and watch around the pen.
3. farm animals should float outside fence, then teleport back in when you get close.
Related issues
Comments


Mobs (not just the farm animals) glitch through everything: fences, walls, slabs, full blocks. This issue has seriously been around forever, so I doubt it will ever be fixed.

I have the same problem too... Can this problem to be slove... Is very annoying...
This issue has two issues in one, and both are duplicates. I found the one for case 2. MC-2025
but couldn't find the other now. EDIT: ah, the other one is MC-10 and seems to be fixed already.