Let's answer this question slowly: Is hanging a viable execution method on a ship at sea?

Hanging is typically set up using rope. Ships have plenty of rope on board because their operation relies heavily on rope. So the answer is yes.