The oath military officers take is to “obey LAWFUL orders” No officer is obligated to obey an order that is not lawfully given. If you make that decision though, you better be right!!
"One notable difference between the officer and enlisted oaths is that the oath taken by officers does not include any provision to obey orders; while enlisted personnel are bound by the Uniform Code of Military Justice to obey lawful orders, officers in the service of the United States are bound by this oath to disobey any order that violates the Constitution of the United States."
Officer.