Lot of different things seem to cause it.
Today I edited some terrain as I was planning out a distant section of my zoo for a Bear Mountain (large mountain with waterfalls around which I am going to build habitats for all the bear species). This area was at least 200 meters away from any existing habitat in my zoo, but when I finished I returned to the populated part of my zoo to find that every animal in 6 different habitats was boxed. This happens to me a lot when I do terrain work, though the shear number of affected animals in this case was a lot more than normal, so was the scope of the terrain work I did.
Other times animals nearby get boxed just when I'm working on a construction project in the vicinity of their habit. And other times it happens when I haven't done anything....always with climbers in that instance though, so I think sometimes climbing bugs out and it just boxes them.