It's instinctive to those with the instinct. What happens if every officer is taken out except a YO - do they assume command?
One of the things the Navy does. is to avoid having "all the officers except the acting subbie" in one place for convenient obliteration, and the AS/Lt will likely be in the Ops Room, listening and learning and trying not to panic, during action; so will be taken out in the first hit and conveniently removing the problem.
For real giggles, what do you do when all your occifers are hors de combat but you've got a civilian searider who (a) helps teach PWOs and EW teams anti-ship missile defence, (b) had a "CS equivalent rank" that was notionally senior to the CO (while they were still alive?)
(The answer, by the way, is you ask them for tactical advice and keep them right in their box, they may be experts inside their bubble but they're entirely clueless of many important elements of managing and fighting the ship outside it, and by the time they're good at their day job, they know that and have some idea where they can help and where to shut up)
In similar vein, a RNR acting subbie aboard for two weeks of sea time (part of their training) will, if the ship goes to Action Stations, muster with the spare hands and accept direction from qualified personnel - they might be baby officers, but they're not trained or able to do more than carry the back end of a stretcher to get casualties out, and haul drums of firefighting foam forward. So, they're just another unskilled body to use where useful and their job is to "be useful if possible, while not getting under the feet of the SQEP"
In the Arrmy, a 2Lt was at least "able to command a dismounted platoon attack", if not with any guarantee of martial brilliance; the case of "every other officer on the ship is dead" is like asking a fresh-from-RMAS subaltern to take over fighting a battlegroup with a couple of companies of infantry, an armoured squadron or two, and artillery and airpower in support while co-ordinating with the rest of the brigade.