The AI surrender behavior can seem a little arbitrary. Many people complain it surrenders "too soon", but after reviewing several replays I concluded that - if anything - the AI waits far too long to surrender. Generally speaking the AI has been losing a battle of attrition for over an hour by the time it surrenders, and it's barely capable of maintaining a credible defense of a handful of planets.
Usually the pattern works like this:
The AI falls behind its opponents economically. It struggles to maintain a similarly-sized fleet and generally goes above what its upkeep limit can confortably support. The AI then takes excessive casualties in a major battle, but due to its uncomfortably high upkeep, it cannot replace them very quickly. The AI's fleet quickly deteriorates in strength and it is unable to defend itself against any credible incursions. The AI's attempts to regroup, but this just leads to further deterioration of its position. At some arbitrary point, the AI throws in the towel and surrenders. Often times it still has considerable assets left at this point, but it's economy is in tatters and its fleet isn't strong enough to defend what little it has left. Although it might have a last stand ahead of it, this can only end one way.
The problem is the "regroup" step. The AI retreats and abandons its assets, only weakening an already losing position. This would make sense if it had allies and its goal was to hold out as long as it can, but if the AI is on its own then this is just prolonging the inevitable, and ultimately it leads to an anti-climatic surrender when it should have made its last-ditch counter-attack an hour earlier. It also leads players to expect the AI to put up a "last stand", and it is very unrewarding when, after a long game of playing cat and mouse, the AI surrenders rather than giving the player this gratification.