Anecdotal second-hand sea story follows, so take this with a grain of salt…
Back when I was in the Navy, I heard about this one submarine CO, who was not just a screamer (which wasn’t all that unusual), but also had a habit of pushing people forcefully up against bulkheads when he was unhappy with them (and he was always unhappy).
Anyway, word reached his superiors of this unacceptable behavior at the submarine squadron, so the squadron chief of staff (squadron second-in-command and a full O-6 Captain), was sent to ride along with the submarine for a two-week op. The submarine CO (an O-5 Commander), must have suspected that something was up, so he was on his best behavior.
However, just a few days before they were due to return, old habits reasserted themselves, and he started screaming at sailors again in the control room, culminating in him slamming a sailor up against the bulkhead right as the Chief of Staff entered the control room.
That was apparently enough for the Chief of Staff. He could have waited until the sub got back to port, but instead announced loudly, “Attention in Control, CMDR is hereby relieved of command of USS . CAPT hereby assumes command. Quartermaster of the Watch, record this in the ship’s log. CMDR , please confine yourself to your quarters.” After the (former) CO left the control room, the Chief of Staff made a similar announcement over the 1MC (shipwide announcing system).
When they got to port, the former CO quietly left the ship. The Chief of Staff was the temporary CO for a few weeks until a new CO was selected.
Anyway, this is the only situation in which I heard that a CO was actually relieved of command at sea for cause.
Usually when a CO screws up (such as running aground or a collision at sea), he is relieved of command upon returning to port. This actually happens surprisingly frequently. Not long ago, it seems like a month didn’t go by without a CO being relieved of command for cause.