If not all seven slots in the army are occupied, the gate can be held by just one or two units, separated from the main stack (as long as they have enough health to reach the gate). The point is that a fallen unit of the attacker still continues to block the enemy's gate – it's like Alexander Matrosov... :) And the main stack can engage in a full-fledged melee.
Added 1 minute ago
I misspoke; when I mentioned the strange behavior of the computer, I meant the situation when the computer is attacking a castle.