Must captains go down with their ships?

Certainly, there is a moral obligation for the captain to stay to the last. There is also a reasonable expectation that the master will remain on board to best exercise his responsibilities and attend to the safety of his passengers and crew and their orderly and safe evacuation after an abandon-ship order has been given. The captain’s presence and authority are absolutely necessary to maintain discipline in emergency situations.

But that is distinct from a legal obligation to remain aboard, much less to perish with the ship. Consider the case of Captain Edward Smith of the RMS Titanic, which struck an iceberg and sank in the North Atlantic in April 1912. A few minutes before the vessel went down, Smith was observed walking to the wheelhouse. His body was never recovered and he is believed to have gone down with his ship, even though he could have tried to get on a lifeboat or taken other steps to save himself.