I see where you are coming from. Yes you can play the AI with the gate quite well but:
1. You have to have a superior force altogether to fend off their attacks everywhere (the fleet still needs to drag itself back to the gate or to the nearest planet being attacked in normal speed)
2. The larger the map and later the game this time increases considerably.
Thus the exploit itself only works on small maps, early game and with a superior force. But if you have the later it makes more sense to take the offensive -AI will take on larger forces when defending.
The retreat logic makes sense as there is no strategic value in throwing away a fleet against a superior force (human players would do the same)
Where the AI might need further improvement here is how it orcastrates attacks. Having more (if smaller) attack fleets might help them exploit weak spots in the defence better though it would also lead to more micro and ironically also to more retreating fleets overall