In the US military (and I would assume all militaries?) a servicemember must obey an order from a superior officer if the order is lawful; however, if complying would require the commission of a crime, the order is unlawful and must be disobeyed. Would a court-martial ever rule that it would have been legal to obey an order, but the servicemember reasonably believed it was unlawful and was therefore justified in refusing to comply? Has such a ruling ever actually happened?
They would commit a prima facie offence contrary to section 12 Armed Forces Act 2006:
12 Disobedience to lawful commands
(1) A person subject to service law commits an offence if—
(a) he disobeys a lawful command; and
(b) he intends to disobey, or is reckless as to whether he disobeys, the command.
(2) A person guilty of an offence under this section is liable to any punishment mentioned in the Table in section 164, but any sentence of imprisonment imposed in respect of the offence must not exceed ten years.
325 Evidential burden as respects excuses
(1) This section applies to an offence under any of sections 1 to 41, 93A, 93E, 93G, 107, 229, 232G and 266 which is such that a person who would otherwise commit the offence—
(a) does not do so if he has a lawful excuse; or
(b) does not do so if he has a reasonable excuse.
(2) In proceedings for an offence to which this section applies, the defendant is to be treated as not having had a lawful excuse or reasonable excuse (as the case may be) unless sufficient evidence is adduced to raise an issue as to whether he had such an excuse.
1Although tagged united-states, I have answered in line with: we expect and encourage answers dealing with other jurisdictions ... please tag your answer using the tag markdown: [tag: some-tag]" from the Help centre
Let's look at the UCMJ text.
Art. 92. Failure to obey order or regulation
Any person subject to this chapter who— (1)violates or fails to obey any lawful general order or regulation; (2)having knowledge of any other lawful order issued by a member of the armed forces, which it is his duty to obey, fails to obey the order; or (3)is derelict in the performance of his duties; shall be punished as a court-martial may direct.
There is a tremendous amount of case law contained in "lawful order." A key concept is that orders are presumed to be lawful, so the burden of proof for unlawfulness will be on the defendant. I could find no case (not that I know how to actually search federal military cases) that applied the defendant's state of mind ("mens rea") as to lawfulness of the law as a defense here. Basically the defendant will have to show that the order was unlawful; the member's belief in unlawfulness is not at issue.
Mens rea issues tend to be if the defendant understood the order, or what the defendant's state of mind was when they were performing the activity they are charged for (like did the member know they were giving alcohol to an underage person). These are not choices to disobey an order due to perceived unlawfulness.
Certainly I would not say that no Court-Martial would ever rule differently - these courts and juries have wide latitude to choose outcomes. I do however feel like this defense would be hard to pull off.