If those were solid blocks, the animal would suffocate if they were fences or transparent blocks, the animal could be pushed right through them.
Note: In older versions of Minecraft, overcrowded animals could be pushed into the walls of the pen.
Do not kill all of them, as it will be harder to breed animals again.