In Star Trek, a lot of the regulations quoted are throw away references. Many of them never occur again, even if they probably should. It's one of the problems with episodic television with different script writers.
That said, the authority of an medical officer to relieve an officer of duty is a significant plot element in the TOS episode The Doomsday Machine. In that instance, the regulation cited is Starfleet Order 104, Section C. Starfleet Order 104 relates to flag officers taking command of a ship, and Section C specifically covers medical officers relieving flag officers of that authority.
Based on conversations with friends and family who have served, in the real world, there are a few different kinds of authority that can potentially interleave in interesting ways. The precise regulations vary from country to country, and sometimes even within the same country (US Army protocols are similar, but not identical to US Navy protocols), so I've abstained from providing links to any single nation's regulations. Instead, I'll cover it in broad strokes.
General authority derives from oaths of office, law, rank structure, traditions and regulations. For example, this authority gives a soldier the right (and obligation) to stop a fight between fellow soldiers, regardless of unit membership. It even applies when you're off duty and out of uniform; it allows one soldier to tell another soldier "Hey, fix your uniform, it's out of regulation." In effect, the authority doesn't come from the individual soldier, but from the regulations they've all sworn to obey.
Command authority is based on your rank and assignment. This is the authority that creates the "chain of command". Orders from superiors flow down this chain; in the civilian world, this is your boss and your bosses' boss and so forth. Orders related to your job but from outside of your chain of command are not legitimate orders. The exact protocols and traditions vary from military to military, of course.
Positional authority is derived from your job, but it also exists and extends outside of the chain of command. This the means by which a medical officer can relieve a superior of duty. The skill set of a medical officer gives him training and knowledge that supersedes that of the non-medical officer; regulations are written to provide him the legal right to use that training in the performance of his duties. This is also the authority that permits enlisted Military Police soldiers to arrest officers and ignore any order that officer may issue to the contrary. Likewise, it gives a military sentry the authority to issue orders to anybody crossing his line of responsibility, again regardless of rank.