The description of the application of German treason law to Poles in the Incorporated Eastern Territories (= the western provinces of Poland annexed by Germany) as "illegal" depends on an acceptance of the position taken by France and Britian, and later by the Soviet Union and the United States, that the claimed annexation was invalid since it had not been agreed to by the Government of Poland, and that therefore the territories concerned had not become German sovereign territory, with the population living in them subject to German law, but rather remained Polish sovereign territory under German occupation, with the occupation authorities legally obliged to adhere to the existing international law governing belligerent occupation.Hence, the illegal application of German treason law to Poles in the incorporated Eastern territories was found to be a war crime in The Justice Case, because the domestic law of an occupying power cannot be extended to the inhabitants of occupied territories in that way.
The position of the German Government of course was that it had legally annexed the western provinces of Poland, and that they were now part of the sovereign territory of the German State, with their population, both ethnically German and ethnically Polish, subject to German law, including the law defining acts that constituted treason against the State. The German Government took the position that the inhabitants of the annexed territories were no longer enemy civilians protected by the international law applying to the treatment of civilian populations under occupation, but rather persons legally subject to the sovereign power of the German State, either citizens of the German Reich (the status of ethnic Germans) or so-called "Schutzangehoerige", stateless persons under the protection of the German Reich.
The German Government's claim to have legally annexed the western provinces of Poland did contain some anomalies however. Thus, while those territories were brought within the customs and currency borders of the German Reich, they were excluded from the jurisdiction of the German courts, and German law was applied by police courts, which were not subject to oversight by the German judiciary.
After the war, the Military Tribunals established by the Allied Governments accepted the position taken by those Governments on the status of the Polish western provinces, ie that they had not become German sovereign territory, and that therefore the German Government had no legal right to introduce its own laws into those territories. That acceptance was inevitable, since the Military Tribunals were obliged by their statutes to accept any declaration made by the Allied Governments.