Anyone who’s ever watched any of the various incarnations of Star Trek knows that sometimes things get a little dicey out in space and you can’t always rely on Starfleet Command to give you the best orders. No one in the history of ships named Enterprise has been quicker to disregard Starfleet’s orders than Captain James T. Kirk. He’s even been demoted from a position as Admiral for disobeying Starfleet (Star Trek IV: The Voyage Home). There are many examples of Kirk being a bit of a loose cannon when it comes to the orders of his superiors, and despite the fact that it usually works out for the best (like saving Earth from an alien probe that will only talk to whales) is Kirk always doing the right thing?
Let’s take a look at another example that’s a little less charged than the fate of the world. In The Original Series episode “The Amok Time” (season 2 episode 1). Kirk is ordered to attend an inauguration ceremony on Altair VI while at the same time Spock begins to undergo the Pon Farr (Vulcan time of mating) and must get to Vulcan or he will die. Kirk requests permission to divert to Vulcan so that he can save Spock but Starfleet denies his request and orders him with all speed to Altair VI. Surprising no one, Kirk diverts to Vulcan to save Spock (then has to fight him to the death; you just have to watch the episode).
So what happens when Kirk needs to report back to Starfleet? Well, let’s assume that Starfleet has something akin to our Code of Military Justice Article 92: Failure to Obey Order or Regulation which subjects US Military members who disobey a lawful order to dishonorable discharge, fines, and up to 2 years in jail. Kirk was clearly given an order from Starfleet and we have absolutely no indication that the order was unlawful. We can easily assume that Kirk is bound to follow the orders of his superiors, so why then does he get to stay as Captain for another two seasons?
Kirk could rely on what US law refers to as the choice of evils doctrine. This is exactly what it sounds like, in a situation where you are forced to choose between two bad outcomes you aren’t criminally responsible for choosing the lesser of those two evils. Starfleet Regulation 3 Paragraph 12 seems to mirror our choice of evils in some respects, authorizing a captain to take any justifiable action to preserve the lives of their crew when threatened with imminent destruction (Voyager season 5 episode 26 “Equinox”). In Amok Time, Kirk tells Bones that he is familiar with the Altair VI situation where the Enterprise would be one of three ships showing Starfleet’s support and is not crucial to the event so Kirk must balance that with saving the life of Spock who Kirk says is considered by some to be the best first officer in the fleet. Kirk is forced to balance those harms and chooses to save Spock. A Starfleet court-marshal would have a difficult time saying that Kirk without a doubt made the wrong choice.