This from Military.com on unlawful orders:
"I was only following orders," has been unsuccessfully used as a legal defense in hundreds of cases (probably most notably by Nazi leaders at the Nuremberg tribunals following World War II). The defense didn't work for them, nor has it worked in hundreds of cases since.
The first recorded case of a United States Military officer using the "I was only following orders" defense dates back to 1799. During the War with France, Congress passed a law making it permissible to seize ships bound to any French Port. However, when President John Adams wrote the order to authorize the U.S. Navy to do so, he wrote that Navy ships were authorized to seize any vessel bound for a French port, or traveling from a French port. Pursuant to the President's instructions, a U.S. Navy captain seized a Danish Ship (the Flying Fish), which was en route from a French Port. The owners of the ship sued the Navy captain in U.S. maritime court for trespass. They won, and the United States Supreme Court upheld the decision. The U.S. Supreme Court held that Navy commanders "act at their own peril" when obeying presidential orders when such orders are illegal.
The Vietnam War presented the United States military courts with more cases of the "I was only following orders" defense than any previous conflict. The decisions during these cases reaffirmed that following manifestly illegal orders is not a viable defense from criminal prosecution. In United States v. Keenan, the accused (Keenan) was found guilty of murder after he obeyed in order to shoot and kill an elderly Vietnamese citizen. The Court of Military Appeals held that "the justification for acts done pursuant to orders does not exist if the order was of such a nature that a man of ordinary sense and understanding would know it to be illegal." (Interestingly, the soldier who gave Keenan the order, Corporal Luczko, was acquitted by reason of insanity).
Probably the most famous case of the "I was only following orders" defense was the court-martial (and conviction for premeditated murder) of First Lieutenant William Calley for his part in the My Lai Massacre on March 16, 1968. The military court rejected Calley's argument of obeying the order of his superiors. On March 29, 1971, Calley was sentenced to life in prison. However, the public outcry in the United States following this very publicized and controversial trial was such that President Nixon granted him clemency. Calley wound up spending 3 1/2 years under house arrest at Fort Benning Georgia, where a federal judge ultimately ordered his release.
In 2004, the military began court-martials of several military members deployed to Iraq for mistreating prisoners and detainees. Several members claimed that they were only following the orders of military intelligence officials. Unfortunately (for them), that defense won't fly. The mistreatment of prisoners is a crime under both international law, and the Uniform Code of Military Justice (see Article 93 — Cruelty and Maltreatment).
It's clear, under military law, that military members can be held accountable for crimes committed under the guise of "obeying orders," and there is no requirement to obey orders which are unlawful. However, here's the rub: A military member disobeys such orders at his/her own peril. Ultimately, it's not whether or not the military member thinks the order is illegal or unlawful, it's whether military superiors (and courts) think the order was illegal or unlawful.
Take the case of Michael New. In 1995, Spec-4 Michael New was serving with the 1/15 Battalion of the 3rd infantry Division of the U.S. Army at Schweinfurt, Germany. When assigned as part of a multi-national peacekeeping mission about to be deployed to Macedonia, Spec-4 New and the other soldiers in his unit were ordered to wear United Nations (U.N.) Helmets and arm bands. New refused the order, contending that it was an illegal order. New's superiors disagreed. Ultimately, so did the court-martial panel. New was found guilty of disobeying a lawful order and sentenced to a bad conduct discharge. The Army Court of Criminal Appeals upheld the conviction, as did the Court of Appeals of the Armed Forces.