Yes it could. Flag officers who are qualified to command at sea do have authority over a vessel's commanding officer, even if the flag officer is only aboard as a passenger, US Navy Regulations Art. 1031 Sec. 1. A captain or below, even if senior to the vessel's CO, would not have that authority. Being a captain is a big deal, but being an admiral is a bigger deal.
The flip side of that is that if things went bad, the flag officer would bear most of the blame, too.
What could not happen in the USN is the situation in "The Deadly Years," because Stocker would not be qualified to command at sea.
I think, besides regulation, Kirk would be well served when he regains his youth in raking his bridge crew over the coals. Just as in Turnabout Intruder, some security guards should get demotions.
Deadly Years: "The fuck is wrong with you all??? use your heads!!! I don't care if its in the regulations, a Commodore orders you to violate the Neutral Zone...you don't just go along with it!!"
Turnabout Intruder: That dude who told Spock "You're as crazy as she is!!"