That's not really the case. A nation's EEZ (exclusive economic zone) extends at least 200 miles, within which a nation has certain rights to regulate economic activities. The flag country has jurisdiction over the ship at all times. And, the flag country can make whatever arrangements they want with other powers. For instance, it's routine for the US Coast Guard to stop ships travelling in "international waters" because it has agreements with, eg, the government of Panama that it may do so.
http://en.wikipedia.org/wiki/United_Nations_Convention_on_th...
I wonder why countries allow this. For example, by withholding (dis)embarkation services from vessels known to be flouting the local tax system. It's one thing to travel around the world on a ship registered in Panama. It's another to book a one-night hotel stay on a ship which never leaves radio distance of your home, yet claims no tie to your country.
For example, http://cruise.expedia.com/Itinerary5.aspx?item=849031 is a foreign-built foreign-flagged ship that departs from San Francisco, docks in Los Angeles, and has a final destination of Miami. This is permitted because the itinerary includes a port outside of North America.
Plus, the PSVA is implemented as a monetary fine. There are cruise lines that will let passengers violate PSVA for an additional fee.
[1] https://en.wikipedia.org/wiki/Passenger_Vessel_Services_Act_...