Per the United Nations Convention on the Law of the Sea (UNCLOS)
Article 95 of UNCLOS: Warships on the high seas have complete immunity from the jurisdiction of any State other than the flag State.
Article 96 of UNCLOS: Ships owned or operated by a State and used only on government non-commercial service shall, on the high seas, have complete immunity from the jurisdiction of any State other than the flag State.
1) An interesting case came up: Argentina's frigate (well, a historical tall ship, but it was technically the flagship, like the USS Constitution) the ARA Libertad was seized in Ghana related to the $100b sovereign debt default of 2001, and a NY federal district court judgment for one of the bondholders against Argentina.
2) The whole point of a warship is that you can't detain it; if it fails to be able to prevent detention, it's not really very good as a warship, is it?
3) Ragnar Danneskjøld