One of the story arcs of TNG was about Commander Troi becoming Line Certified so she could “have the Conn”… you will no doubt recall how that worked out for everyone in Star Trek: Generations. That said, following the model of the U.S. Navy – which was Rodenberry’s influence at any rate, there are two types of officers: Line officers and Staff Officers.
To understand the difference you would need to understand that differences between various types of authority:
Line Officer vs. Staff Officers: Line Officers are trained and certified to Command, they are Bridge Certified and can “Have the Conn”, stand Watch on the Bridge, and generally lead away teams. Staff Officers are trained as experts in a functional role, and while they are trained to administrate or lead, they lack the tactical training and crisis leadership expertise of a Line officer. All Command Branch officers are trained as Line Officers at the Academy, all other Branches are not and require additional training for this as explored by the Bridge Certification and to a lesser extend Department Head continuing education training the pursue later in their careers.
Positional Authority: This is authority that comes with one’s job or position. Examples of this include but are not limited to a Security Officer detaining a superior due to an investigation or arrest; a Doctor medically relieving a superior officer for medical reasons; a Starfleet Intelligence officer ordering information or logs restricted in access for security reasons, the designated pilot of a shuttle directing other passengers in what to do, etc. If you outrank someone but they are in command of a station or ship you are a passenger on, technically their position gives them authority over you unless you usurp that command. Positional Authority trumps rank and line authority, but one must be careful when invoking it as it typically is situational. Line vs Staff authority is technically a form of positional authority, but it is broad and rarely only situational.
Rank Authority: The easiest to factor – The person with the higher rank is in charge but this is mitigated by position and Line vs Staff, and of course by chain of command. I am now seeing Mr. X addressed all this so I am perhaps being redundant and I won’t go further into this aspect.
So how do you determine this on your ship or station? The easiest way for me is to start with the Red Shirts – how many are on board? Typically this is the smallest depart, but all of the officers are Line Officers so I put them in a line based on rank/position. On a smaller ship you probably have the C.O., X.O. three helm officers and may one or two others, but maybe just those five. Then you go to the 2nd officer, typically the Operations Manager. Then you go through the senior staff who are Line Certified – slap those into the command chain based on rank. After you have the Line officers, you go by department and rank. Status of precedence for Star Fleet is: Command, Operations, Engineering, Security, Science, Medical. So if you have two Lieutenant J.G.'s and one is Security and one is Medical and neither are staff and its not a security or medical matter, the Security officer is nominally in charge by default.
Executive Officer (1st Officer)
Chief of Operations (2nd Officer)
Chief of Engineering (3rd Officer)
Flight Control Officer (4th Officer)
Assistant Flight Control Officer - LTjg (5th Officer)
Logistics Officer (6th Officer)
Assistant Flight Control Officer -ESN (7th Officer)
Assistant Flight Control Officer - ESN (8th Officer)
CSec – LT (9th Officer)
CSci – LT (10th Officer)
CMed – LT (11th Officer) etc
So even though the Chief of Security outranks a majority of the Line officers, because he is a Staff officer he defers to them in the Chain of Command except when it relates to matters of his department, unless they actively have the Conn or are the Away Team leader, then he defers regardless. Likewise, Ensign who is the 8th officer defers to the CSec when he is acting on a security matter unless they are actively in command, but outside of a security matter they don’t actually report to or have to take orders from the Chief of Security.
Anyway, that’s how it goes down in my games – I take the above point about Star Fleet only being a paramilitary organization Mister X put forward, my own experience IRL in the Boy Scouts still said rank and position mattered in situations about who was in charge, when and of what and my experience in the actual military definitely defined that. I’ve never had players sperg out about this, but then I don’t really have entitled snowflake players in my game either who might be set off by such a thing. YMMV, Peace.