The US military has laws that essentially say that everyone has a duty to ignore unlawful orders, and if you follow unlawful orders you will be held accountable for your actions. Did the German military in the 1930's have a similar law or code?
The US military has laws that essentially say that everyone has a duty to ignore unlawful orders
This is not quite correct for this time period. Both the American and British regulations for unlawful orders stated that it was the duty of the soldiers receiving these orders to obey them within reason. The 1929 British Manual of Military Law stated:
It is important, however to note that members of the armed forced who commit such violations of the recognized rules of warfare as are ordered by their government, or by their commanders are not war criminals and cannot therefore be punished by the enemy. He may punish commanders responsible for such orders if they fall into his hands but otherwise he may only resort to the other means of obtaining redress which are dealt in this chapter.
Likewise, the American 1940 Basic Field Manual Rules of Land Warfare placed the onus for illegal orders on commanders, stating:
Individuals of the armed forces will not be punished for these offenses in case they are committed under the orders or sanction of their government or commanders. The commanders ordering the commission of such acts, or under whose authorities they are committed by the troops may be punished by the belligerent into whose hands they may fall.
American field regulations further stated that while soldiers had a duty to obey orders, they needed to respect the chain of command and not engage in open defiance but work through proper channels.
German military law had much of the same language and responsibilities as Anglo-American military law. §. 47 of the Militär-Strafgesetzbuch für das Deutsche Reich stated:
If carrying out an order in the course of duty should violate a law, only the superior who gives the order is responsible. However, the subordinate who obeys it is punishable as a participant: a.) if he goes beyond the given order or b.) when he knows that the superior's order would have the aim of leading to military or other crime or violation.
This regulation dated back to the Kaiserreich and remained in force during the Third Reich. Like Anglo-American contemporaries, the onus of legal responsibility was largely on the commanding officer giving the orders.
The Anglo-Americans did hastily rewrite their regulations in 1944 to reflect greater individual responsibility for unlawful orders with an eye towards prosecuting Germans for violations of the rules of warfare (note in the linked American manual, the relevant section has been physically crossed out on p. 87). German defense at the IMT and NMTs would point out the Allied policies and late changes, but the Tribunals forbid such a tu quoque defense.
German military authorities were aware of §. 47 and its implications for destroying racial enemies of the state, but either the Germans ignored these restrictions or crafted their own orders that declared them null. The most salient example of the latter was the Barbarossa Decree of 13 May 1941 in which OKW declared that there was “no compulsion to prosecute,” criminal offenses committed by Wehrmacht troops against enemy civilians unless such offenses directly hindered German military objectives. Other decrees like the Commissar Order sidestepped procedures in favor of more violent and immediate measures. However, despite these various edicts, the legal mechanisms of German military justice remained intact. The historian Christopher Browning has found that of the decidedly small minority of Germans who did refuse orders to commit war crimes, none suffered any punishment or court martials.
The problem German war crimes presented to military justice was that they were of a different species of unlawful orders that then existing military law was ill-prepared to handle. Most legal jurisprudence on unlawful military orders were predicated on the idea that the offending officer was acting in a rogue manner and violating the laws of war. These violations could either be for one’s personal enrichment or fighting their own kind of war such as shooting prisoners or using illegal weapons like gas. The problem for German war crimes was that these orders were not counter to state policy, they were state policy. Orders to execute civilians and other genocidal acts emanated from the very upper echelons of the German state. Most of the corpus of existing military law treated such unlawful orders as the exception, but in Germany’s war, they were the rule. This was one of the reasons why postwar military laws had to be rewritten extensively to accommodate what to do when a state's leaders violate the rules of war and its soldiers carry out their orders.