If the AI units in the fortress gate would be able to retaliate (i.e. if the attacking unit is adjacent to the fortress gate), then the AI will always choose to assign damage coming to their fortress gate to the units still in the fortress gate.