This is a concern definitely.
You could make the AI try to haggle for peace at the point of having no shipyards, this is a valuable observation in it's concerns for when to offer a peace treaty. Also a MASSIVE concern in what it needs to defend, and prioritize for defensive actions.
Of course if the player doesn't want peace, what can the AI do with 0 shipyards. Well it can prioritize trading for ships with other races.
I also wouldn't be against a minor race group called mercenaries (or just use the pirate group I suggested before), whereby you can pay them to engage in wars you are engaged in, they have a temporary alliance with you or the the AI while you are at war and paying them. The alliance would cancel when you come out of wars, and/or don't pay them
Old Pirate Race Suggestion - https://forums.galciv3.com/460354/page/1
Even just a button the AI can use called pay mercenaries, no group attached, so if it is ever in this situation it can pay some rogue ships to try and lift a blockade or defend a certain starsystem long enough for it to get a shipyard up.