I've been wondering how exactly you do this kind of stuff?
The AI in this game is not a black box in the way that an LLM is. It's a set of explicitly programmed instructions that uses the current state of the game as its input to appear "intelligent". This is also called an expert system. Some people consider this a form of AI and others consider it the exact opposite of AI. (This is probably because AI really has no clear meaning.)
In practice that means a lof of "if this then that" logic or code that computes a score according to some arbitrary formula to determine the best choice (e.g. compute a score for each unit and then pick the unit with the best score). Often this is just a sequence of things to do and then doing the first thing that's applicable e.g. does this city need a defender? Then build a defender. Otherwise, does this city need culture? Then build culture. Otherwise does this city need workers? Then build workers etc.
If all of this sounds very arbitrary to you and kind of like it shouldn't produce intelligent outcomes, you are right. But still arbitrary logic is often still good enough as long as it's consistently followed and doing nothing too stupid. If you ever wonder why video game AIs are so terrible it is because they are all implemented more or less like this. The worst aspect of this approach is that all the arbitrary rules need to be tuned correctly along with everything else so the rule that makes the AI build ships (to pick a random example) isn't valued much higher than something else in the system, even though these rules are entirely independent of each other.
With that explanation out of the way I can actually answer your question.
I know where the code for all of this is. Somewhere in the logic there is one (or likely, multiple) steps that say "If we need ships, and if this is a city that should build ships, build ships". If those conditions are satisfied the city will build a ship and not consider any of the subsequent steps. So either anything the city could be doing that is considered before ships is for some reason not considered necessary, or building ships is considered necessary despite there already being lots of ships.
That's why I am asking for saves - the "do we need ships" check looks at the game state to determine if ships are needed. Looking at it without the context of a particular save would just be guess work. Ideally I have a save where the AI decides to build a ship, I figure out the reason for this misjudgement and address it, and then I load the save again and the AI decides to do something else.
In practice often this means to go into the code and print lots of debug messages like "considered x, rejected for reason y" or "decision x score is y" and then try to sort through the output. You can also use the IDE to suspend the game when a particular line of code is triggered to inspect the current state of the game including variables and inputs and so on. Even with these tools it is a lot of information to go through and try to make sense of, which is why it's impractical to just run autoplay and look at it. Having a save where the situation already exists really is the only way to make the effort worthwhile and I still kind of loathe spending my time on it.
My guess here by the way is that the cause are the new AI rules I introduced to make the AI build settlers and ships for these settlers. It's a classic example where there was already a path for the AI to do this, but it was so far down in the priority list that it was unlikely to happen. For example, when America was stuck never building settlers it was because the AI considers improving city production a higher priority than building settlers. So America started with the ability to build Levees and all cities immediately started building Levees. Long term not a bad decision, but that bogged down all cities trying to build this expensive building with their low initial production.
So I added a new condition to build settlers that precedes a lot of other things alongside a check (or so I thought) to make sure this isn't taking over the priorities of every city in the game. I think for settlers I did a good job at that but perhaps there is an issue with the condition for ships needed. But that's just a first guess.