A senior officer could take command of the overall mission of a naval vessel today. He wouldn't be able to override the CO of that vessel on matters directly relating to the operating of said ship, though. Say, he could order a near-suicidal run through narrows straddled by enemy anti-ship missile batteries, if that's what best served the strategic aims of the navy, but he couldn't tell the CO to make that run over sandbars, or at a speed that would make the last surviving turbine tear apart. It would be up to the skipper to manage such issues.
In "DDM", I trust Starfleet would side with Decker on the necessity of stopping the planet-eating beast even at the cost of casualties to Kirk's starship, or ultimately the loss of said ship. Kirk couldn't refuse Decker's orders on the basis that they endanger his ship, as Kirk's oath was to die for the 23rd century equivalents of king and country. However, the two could argue the wisdom of Decker's approach literally till doomsday, and if Kirk's argument prevailed, Starfleet might defend his refusal to follow Decker's not-so-smart plan.
As for Spock being so eager to hand over the ship to Kirk in ST2, I'd say it had less to do with Starfleet regulations and more to do with friends, egos, and Kirk's birthday... Spock was theoretically allowed to relinquish command, so he readily did.
Timo Saloniemi