It will have to. The suggestion is that if you sail too close to another ship while flying a false flag, that makes it suspicious of you even if it can't recognise you by reading your name or see your face. Since this is inevitable when you approach a port and another ship is near that port, we're back to the situation where you're automatically detected by any ship in the area.So the AI has to check the location of the ports relative to its own position now too?
The point is that running away from a warship which is flying a (possibly false) friendly flag is illogical. You'd be going to a lot of effort to exchange one illogical behaviour pattern for another illogical behaviour pattern.NPC ships don't use false flags (yet? Build 15 idea!) so if you are Dutch, flying a Dutch flag and encountering a Dutch merchant, there is no false flag checking to be done.
On the other hand, the logic does stand from the side of the NPC merchant ship, but again, that is adding more complexity to something doesn't even work right now in a simplified form.
Your worry is that a false flag will only be detected when you're right alongside the other ship. Which indeed it will, if the other ship is only a poor lugger with a novice captain. The pirate's problem is when a frigate with a more experienced captain takes a look at him - higher skill captain and naval ship so it's likely to detect him further away, and that's the sort of ship which can do something about it. Hence my suggestion that ship size should be a factor and so should whether it's navy or merchant.
The other question is, what if there are multiple ships? If there are four ships in the other group, do you check for each ship or for the entire group? If the chance of a single ship detecting you is high enough to be a worry, and you do the same check for every ship in the group, then four (or more) ships will almost certainly get you every time.