This is actually a side effect of something that is otherwise detrimental to the AI:
The AI uses "queued attacks" instead of attacking with units regularly. This means that instead of attacking a target one-by-one like a human player would, the AI queues up all the units it wants to attack with, has them execute their attacks all at once, then move onto the next target. This happens via a bit of code at the very end of the functions that execute attacks to move onto the next unit in the attack queue if the target is still alive.
The big downside of this approach is that the AI has no way to react to high or low rolls: if it ends up being 1 damage short of destroying a target, tough luck, it won't call in one more unit to finish the target off.
The way that Impis' attacks work is that when they execute their melee attack move, a ranged attack move is called before the rest of the melee attack move is executed. The ranged attack move, being a ranged attack, jumps to the next unit in the attack queue when it is finished, but the melee attack move for the original Impi is still running under all of this. If the next unit is an Impi, they pull the same thing, too (melee attack calls ranged attack, then the AI jumps to the next unit while the Impi's melee attack is still waiting to be processed). Then, once there are no more queued units to jump to and the target is still alive, all of the Impis' melee attacks are processed in reverse order. BTW, this also means that if the Zulu AI attacks a target with an Impi and a Knight, the Knight will attack after the Impi ranged attack but before the Impi melee attack.