A very old Dr. McCoy appeared as an admiral in the "Encounter at Farpoint", the first episode of Star Trek the Next Generation.
Presumably he was promoted to captain at some point before that.
scifi.stackexchange.com/users/3025/Keith Thompson
Do alternate realities count?
If so then we have Captain Beverly Crusher :
In an alternate future (the final episode, All Good Things ), Beverly had been promoted to captain and was commanding the medical ship USS Pasteur.
And back in the usual reality, Crusher was given explicit command in the episode Descent : When asked by La Forge who would be in command of the Enterprise
, Doctor Crusher enters the bridge and asks for last orders.
[...] Both officers wished each other good luck, with Picard adding "captain" to her title.
Of course that's the title of Captain rather than the rank of Captain.
There's also Captain Krasnovsky from the ST:
TOS episode Court Martial : Captain Krasnovsky [...] wore a blue sciences division dress uniform, making him the highest-ranking officer to appear wearing science division dress colors, as admiral McCoy's uniform could be either sciences or command.
All other science officers seen on Star Trek were commanders or below.
Krasnovsky was just a bit part
so we don't know if his blue uniform is "medical doctor blue" or "scientist blue"
but I thought I would mention it anyway.
scifi.stackexchange.com/users/13106/mu is too short
In the later movies of TOS team, Kirk, Spock, McCoy & Scotty all held the rank of Captain, even though only Kirk was the actual Captain of the ship.
Do not mistake the rank of Captain with the position/title of Captain.
They are two separate things.
Anyone who is in official command of a ship, regardless of actual rank, holds the position of Captain.
In the US and other navies today, it is common practice that on smaller ships, such as destroyers and frigates, for officers of lower ranks, such as Commander or Lt. Commander, to be in command.
They hold the title and office of Captain, despite not holding the rank.
It is also not unheard of for someone in command of a large ship, such as a carrier, to be of the rank of Admiral.
They still hold the title of Captain on that ship.
scifi.stackexchange.com/users/1551/BBlake
There are a couple of officers who hold the rank of Captain yet do not command a starship: Phillipa Louvois, who was the judge in Data's "trial" in "Measure of a Man".
Krasnovsky, who conducted Kirk's court martial in "Court Martial".
He also wore a blue (science) uniform.
Also, Vice-Admiral Toddman, who worked for Starfleet Security on earth, wore a gold uniform, perhaps implying that he was at one point a non-command captain.
scifi.stackexchange.com/users/1973/Plutor
I don't see why not.
In the US Navy, the senior medical officer is the Surgeon General of the US Navy , who holds Vice-Admiral rank.
Rank doesn't necessarily denote command responsibilities for a ship.
scifi.stackexchange.com/users/712/WOPR
Well if Starfleet patterns its ranks after the US Navy, or Navies of the world, then having physician with the rank of Captain (Colonel), or even Admiral would not be too far.
Since the Captain of a ship is a Naval Officer with Surface Warfare/Underseas Warfare experience, they would be the chief officers of the ship.
Since McCoy would have risen to the rank of Captain, or even Admiral, he could serve as the overall Medical Officer in charge of a major medical Department, on board a much larger Starship.
As for an Admiral, he could be assigned as the overall Medical Officer of a much larger parsec of space, and would have his own staff or floor that would have his own personal offices, or offices for his administrative staff, and his flag would be on that ship.
Now, if McCoy were the senior officer on board a Starship, and all of a sudden all of the senior officers were killed, he may be authorized to take command of the ship for a certain period of time, to get the ship and crew away from the danger.
Then if the ship were now in StarFleet territory, he would probably return command to one of the junior officers, or even a senior Petty Officer.
scifi.stackexchange.com/users/13859/Cam
Because it seems that the writers based the Rate/Rank system in the show on the real U.S. Navy, it's entirely plausible to have a person who holds the captain(O-6 Rate) aboard who is not in overall command of the vessel.
In fact, it's commonplace to have the Commanding officer of an Aircraft Carrier to be a Captain while the Executive officer is also a Captain.
It's just that one is in command and the other is subordinate.
Its the same thing all the way down the line.
I would imagine that Starfleet can, and does, work the same way.
scifi.stackexchange.com/users/14675/user14675
In TNG, Beverly Crusher has the rank of Commander.  Since she is a high-ranking officer, it got me thinking about doctors in general.  Is there a rank for doctors that is higher than Commander?  Could a doctor make it to Captain, even if they are not in command of a starship?  Of course, a doctor with a rank higher than Commander couldn't be on a ship because of command conflict, but I don't see why a doctor with the rank of Captain couldn't serve on a starbase.
Can Starfleet doctors make Captain rank?
scifi.stackexchange.com
<star-trek><star-trek-tng><starfleet-rank>
scifi.stackexchange.com/questions/34116
scifi.stackexchange.com/users/6974/Sponge Bob
If  Starfleet patterns its ranks after the US Navy, or Navies of the world, then having physician with the rank of Captain (Colonel), or even Admiral would not be too far.  It is also not unheard of for someone in command of a large ship, such as a carrier, to be of the rank of Admiral. A doctor can indeed make it to a rank higher than Commander (Admiral): Dr McCoy being the number one example. Also, Phillipa Louvois is a Captain who does not yet command a starship. 
A doctor can indeed make it to a rank higher than Commander (Admiral): Dr McCoy being the number one example. Phillips Louvois is a Captain who does not yet command a starship. 