It is hard. I'll share some of my experience.
I spent many hours on guard duty while in the Army. The first several sessions caused me to go through a lot of "what ifs" concerning the situation. Having never killed anyone before I thought through the moral dilemma of having to take lives in order to save my life or the lives of my fellow soldiers.
Eventually I KNEW exactly what I planned to do and had no doubt whatever that I would be able to carry out the plan. I was fully prepared to kill any number of people to prevent the breach of our site security. After that, guard duty became just hours of boredom.
Commanding a ship or part of a ship would entail the same type of process. I expect that the crew had already thought through the necessity of saving the ship if some incident created a breach below the water line. There wouldn't be time during the incident to weigh the moral arguments. If water is rushing into the ship, you close the watertight doors.
It is through repeated and intensive training that servicemen instinctively react in a way to preserve the ship or the base, no matter the cost.
God bless those who lost their lives, and those who lost their shipmates.