It was unlawful even in the context of wartime Nazi germany
Firstly the order
1. For a long time now our opponents have been employing in their conduct of the war, methods which contravene the International Convention of Geneva. The members of the so-called Commandos behave in a particularly brutal and underhand manner; and it has been established that those units recruit criminals not only from their own country but even former convicts set free in enemy territories. From captured orders it emerges that they are instructed not only to tie up prisoners, but also to kill out-of-hand unarmed captives who they think might prove an encumbrance to them, or hinder them in successfully carrying out their aims. Orders have indeed been found in which the killing of prisoners has positively been demanded of them.
2. In this connection it has already been notified in an Appendix to Army Orders of 7.10.1942. that in future, Germany will adopt the same methods against these Sabotage units of the British and their Allies; i.e. that, whenever they appear, they shall be ruthlessly destroyed by the German troops.
3. I order, therefore:-
From now on all men operating against German troops in so-called Commando raids in Europe or in Africa, are to be annihilated to the last man. This is to be carried out whether they be soldiers in uniform, or saboteurs, with or without arms; and whether fighting or seeking to escape; and it is equally immaterial whether they come into action from Ships and Aircraft, or whether they land by parachute. Even if these individuals on discovery make obvious their intention of giving themselves up as prisoners, no pardon is on any account to be given. On this matter a report is to be made on each case to Headquarters for the information of Higher Command.
4. Should individual members of these Commandos, such as agents, saboteurs etc., fall into the hands of the Armed Forces through any means - as, for example, through the Police in one of the Occupied Territories - they are to be instantly handed over to the S.D.
To hold them in military custody - for example in P.O.W. Camps, etc., - even if only as a temporary measure, is strictly forbidden.
5. This order does not apply to the treatment of those enemy soldiers who are taken prisoner or give themselves up in open battle, in the course of normal operations, large scale attacks; or in major assault landings or airborne operations. Neither does it apply to those who fall into our hands after a sea fight, nor to those enemy soldiers who, after air battle, seek to save their lives by parachute.
6. I will hold all Commanders and Officers responsible under Military Law for any omission to carry out this order, whether by failure in their duty to instruct their units accordingly, or if they themselves act contrary to it.
(Sgd) A Hitler
Was the order lawful
The laws of war, of which Germany was a signatory, as they stood in 1942 were unequivocal on this point: "it is especially forbidden ... to declare that no quarter will be given ". This was established under Article 23 (d) of the 1907 Hague Convention IV – The Laws and Customs of War on Land. The 1929 Geneva convention, which Germany had ratified, defined who should be considered a pow on capture — that included enemy soldiers in proper uniforms — and how they should be treated. While at the time under both the Hague and Geneva Conventions, it was legal to execute "spies and saboteurs" disguised in civilian clothes or uniforms of the enemy, insofar as the Commando Order applied to soldiers in proper uniforms, it was in direct and deliberate violation of both the customary laws of war and Germany's treaty obligations. Hitlers order was therefore unlawful, and the officers who saw the order knew it. At least the one brought before the IMT. The execution of Allied commandos without trial was also a violation of Article 30 of the 1907 Hague Convention IV – The Laws and Customs of War on Land, provided that: "A spy taken in the act shall not be punished without previous trial." This provision only includes soldiers caught behind enemy lines in disguises, and not those wearing proper uniforms. Soldiers in proper uniforms cannot be punished for being lawful combatants and must be treated as prisoners of war upon capture, except those disguised in civilian clothes or uniforms of the enemy for military operations behind enemy lines.
The fact that Hitler's staff took special measures to keep the Order secret, including the limitation of its printing to only twelve copies, strongly suggests that they knew it to be illegal. Several of them during their trials admitted that including (I think) none less than Goering himself. Hitler also knew the order would be unpopular with the professional military, in particular the part of the order that stated that the order would stand even if captured commandos were in proper uniforms (in contrast to the usual provision of international law that only commandos disguised in civilian clothes or uniforms of the enemy could be treated as insurgents or spies, as stated in the "Ex parte Quinn" is a case of the US supreme court during WWII that upheld the jurisdiction of a US military court over the trial of eight German sabateurs found in the US. Quirin has been cited as a precedent for the trial by military commissions across the world. There are similar precedent in German law, though I cant quote them. It was argued July 29 and July 30, 1942, and decided July 31, 1942, with an extended opinion filed October 29, 1942.
This decision states in part that:
... the law of war (established under the hague convention) draws a distinction between the armed forces and the peaceful populations of belligerentss and also between those who are lawful and unlawful combatants. Lawful combatants that are captured must be incarcerated as prisoners by opposing military forces. Unlawful combatants are likewise subject to capture and detention, but in addition they are subject to trial and punishment by military tribunals for acts which render their belligerency unlawful. The spy who secretly and without uniform passes the military lines of a belligerent in time of war, seeking to gather military information and communicate it to the enemy, or an enemy combatant who without uniform comes secretly through the lines for the purpose of waging war by destruction of life or property, are familiar examples of belligerents who are generally deemed not to be entitled to the status of prisoners of war, but to be offenders against the law of war subject to trial and punishment by military tribunals.
The commandos were not afforded this opportunity, which is manifestly clear in the order. It adds to the fact that the order was unlawful, including unlawful under german law.
That a refusal to obey this illegal order would not result in automatic execution is evidenced by the reaction of many officers of the heer. Some commanders like Rommel and Kesselring refused to relay this order to their troops, considering it to be contrary to honourable conduct and illegal. They were absolutely correct