It has been mentioned in many forum posts by many people over the years that passenger AI in mechanized groups are prone to getting into a mount-dismount loop indefinitely when switching to COMBAT behaviour. An APC takes fire, a few troops dismount, the rest stay in, FFV positions start firing, the troops that dismounted maybe take 2 shots and then in turn start to run back to the vehicle to get in (all the while the vehicle is stationary), while some of the troops that were mounted try to dismount. So what you're seeing is instead of an AI group reacting properly to danger, as in all passengers dismounting and engaging enemies/taking cover etc, a group of infantry running back and forth and climbing up and down a vehicle, and another group sitting ducks on top of the vehicle waiting to be shot...
And the even bigger problem, is it's not even possible with any combination of related scripting commands such as setUnloadInCombat, allowGetIn, orderGetIn, unassign/assign vehicle, doGetOut to control reliably the mounting/dismounting behaviour of mechanized AI. The engine just takes over and makes them do whatever it wants, regardless of what you want to happen in this case.
The scripting commands mentioned above are outdated, as they don't behave as expected in the mechanized case (i.e. when vehicle "crew" are supposed to stay onboard and passengers in same group are supposed to dismount, or all are supposed to mount up and vehicle should start moving). The only command powerful enough is leaveVehicle, which forces the group (including crew) to abandon the vehicle completely, which is obviously not what's wanted from a mechanized group.
Especially for AI modders, there should be reliable commands that can control AI behaviour in this case, being able to even override lower level engine behaviour if necessary. This would also enable to stop infantry from climbing on top of tanks in their group when that is clearly not what the missionmaker/modder wants. The easiest way to achieve this would be to have a disableAI "MOUNT" function that forces AI to disembark any vehicle they are in and make it impossible for them to get into any vehicle, and a disableAI "DISMOUNT" that allows AI to get into a vehicle but does not allow it to get out once it is onboard. Unless this is implemented, there is a great need to change the behaviour of the commands mentioned in the second paragraph, which probably would be harder for devs than this easier (at least temporary?) solution.