Depends on what you mean by "allowed". I'm not a lawyer of any kind, but I can tell you from experience that while your oath only requires you to follow lawful orders and we were taught the same while enlisted, if you disobey ANY order, lawful or not, you're in for a world of sh**.
How you get handled will heavily depend on the circumstances, like who's prosecuting you and what the order was. For example, an officer ordering you to vote for a particular presidential candidate is unlawful but much different than say, ordering you to drop bombs on your own base during your next sortie. You will likely not go to jail or lose stripes for refusing the latter order and the officer who gave it would likely end up in prison, but the former might earn the officer a reprimand and maybe a small demotion (depending on their record), but you may still receive some retaliation...
Obviously they can't come after you for disobeying the order after that case is settled, but they can and likely will come after you for literally anything else they can conjure up and usually some variation of finding a dereliction of duty in some unrelated context. For example, late for duty, shoddy work, behavior unbecoming of an NCO, etc. they'll find something and there is almost guaranteed to be some regulation they can pin to your chest. No really. I've watched it happen a hundred times. Even saw an NCO lose 3 stripes and had his re-enlistment denied because his wife got a DUI (off base). That has nothing to do with him at all, but they made it stick, and it was in retaliation for refusing an order to work over 14 hours on the flightline stateside (which is a technical order from the DoD which says you're a danger to yourself and everyone around you after 12 hours). This is super common in the Air Force, I'm not sure about other branches.