(it attacks him because he is at a higher level. The computer seems to always do this.)
The computer attacks in the following order:
1. Archers
2. Flying units
3. Other units
If there are two or more stacks of the same type (archers, flying units, or others), the computer will attack the strongest one. The strength of a stack is calculated as the product of the unit's strength in peasants and the number of units. In this example, the computer will attack the druid only if there are no more than two grand elves. But you can also take 8, but divide them into 4*2 stacks :)
P.S. This order does not apply to some monsters with unique abilities, such as liches and ghosts. The former usually attack two-cell units, the latter attack the weakest, but not always.