Additionally, if a vessel is not flying a flag of any country, it is still subject to certain universal international laws applied to the high seas. The vessel can be subject to any nation’s laws and could potentially be boarded—legally—by any country which suspects the vessel is attempting to hide certain activities or operate outside internationally accepted laws.
Also, they don’t have to know for certain, they just need probable cause to believe a crime is being committed right now - which is the standard requirement for making a lawful arrest. And yes, they must transfer the arrestee to lawful custody ASAP.
Also, in general, military personnel are not law enforcement officers so when a navel officer makes an arrest, it is a citizen’s arrest and they are obliged to hand the detainee over to lawful custody ASAP. The historical term is a “constable at common law”; a term for those authorized by the state to arrest on issuance of a warrant.