It's been mentioned a few times on the forums 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 immediately 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. It's all nice and welcome that mechanized/motorized AI behaviour has improved over the years, but there's no excuse for scripting commands to have no control over something as important as this, especially when it doesn't even work properly in its own right in the first place.
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 doesn't stop AI from getting 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. But I really do think that the final "switch" on whether or not AI are allowed to be in a vehicle at a given time should be under the control of the scripter. A set of disableAI commands here wouldn't interfere with normal AI activity by default, but if a scripter chose to use them, he'd be able to do what he's trying to do.