Basically every senior officer in the German Army and Navy, and most of those in the Luftwaffe, was in uniform when Hitler became Chancellor, and had thus taken an oath to support and defend the Constitution of the Weimar Republic. Ever heard of a senior officer in the German Army, or Navy, getting the boot when Hitler made himself dictator, because he couldn’t violate his oath to the Weimar Republic? Me neither.
Officials do things they don’t want to because:
1. They do have a sense of personal honor.
2. They calculate that the downside of breaking their oath, be the downside social stigma, or being tortured and executed by the Gestapo, is even worse than the downside of doing the thing they are supposed to do, but don’t want to.
And I certainly don’t want to imply senior German Officers were in any physical danger. They were not before at least late 1941. They stood by while Hitler made himself dictator because they despised the Weimar Republic, and they were happy to see him kill it, their oaths be damned.
What you are pointing out, in effect, is that there can be illegal oaths of office.