It happens when the AI is triyng to get inside a wooden gate but has too many unts all stuffed toghether, at least that's the only times i encounter it, and it's always with horse archers.