Yes, this is the mathematical justification for the AI's behavior on the battlefield. The problem is that it's not always possible to quickly account for, assess, and calculate the impact of all factors. The AI's behavior can be defined as the most likely, but that doesn't mean it will act exactly that way – it may act illogically from the player's point of view, but logically according to the algorithm programmed into it. In addition, there may be a certain degree of randomness in the AI's actions in some situations. Therefore, it is not possible to describe the AI's behavior algorithm on the battlefield briefly and unambiguously (without analyzing the code).
However, I would like to note that the "brainless" undead behave as they should – they go to the nearest enemy, while living units may ignore flanking and go directly to the main enemy forces.
Hero - Ain 0/0 (SP and knowledge are not taken into account by the AI when calculating moves). Army - only Gnolls. Let's try two Gnoll formations:
422+6 units and 423+6 units. In the first case, the snakes attack the units. In the second, they rush to the large stack. The difference in damage here is of little importance. Considering the FV of the stacks, we can see that the FV of the snakes = 250*60 = 15000, while the FV of the 428 Gnolls = 70*428 = 29960. The 429th Gnoll acts as the boundary Gnoll that makes the snakes realize that they have no chance. It increases the FV of the Gnolls so much that the ratio becomes >=2. As a result, the first snakes attack the large stack. Then, the snakes see 7 stacks, one of which will not retaliate, but hitting it will result in more HP*FV loss for the enemy. Therefore, all the other snakes attack the large stack as well.
In this way, by adding one Gnoll, you can increase the losses while having a larger army.
By the way, once in a game, everything went wrong in a dungeon because of a larger number of Gnolls. It turned out that the vampire killed by the lizards had reduced the enemy's FV so much that the ratio went beyond the limit, and the skeletons started killing large stacks instead of chasing a single unit. It was something like that, I don't remember exactly.
P.S. With 428 Gnolls, if the large stack is defended in the first round, it will be hit in the second round, even if there is one more Gnoll. The added defense unit seems to be counted not from the creature, but from the hero, and as a result, the stack receives Gnolls with a slightly higher FV, which makes them attack.