"Superior orders, often known as the Nuremberg defense, lawful orders or by the German phrase Befehl ist Befehl ("only following orders", literally "an order is an order"), is a plea in a court of law that a person—whether a member of the military, law enforcement, a firefighting force, or the civilian population—not be held guilty for actions which were ordered by a superior officer or an official.

The superior orders plea is often regarded as the complement to "command responsibility." One of the most noted uses of this plea, or defense, was by the accused in the 1945–1946 Nuremberg trials, such that it is also called the "Nuremberg defense".  It was during these trials, under the London Charter of the International Military Tribunal which set them up, that the defense of superior orders was no longer considered enough to escape punishment..."

( https://en.wikipedia.org/wiki/Superior_orders )

It seems like such oaths are fraught when the war objectively trends immoral and illegal.