Why did Poland get so much territory from Germany in WW2?
Poland was given former German territories by the leaders of the leading powers (Great Britain, USA, USSR) in the course of the conferences deciding the political landscape of post-war Europe. On the first day of Tehran conference held in 1943, during an less formal meeting between Churchill and Stalin, the two leaders discussed potential post-war balance of power in Europe. Both agreed that the Germany must be weakened and isolated to prevent resurgence of the German nationalism for at least half a century and Churchill suggested division of Germany into several elements, stressing that isolation must be especially severe in case of Bavaria and Prussia. Along occupation and creation of the influence zones, both Churchill and Stalin supported the idea of giving Poland part of the Eastern German territories, especially East Prussia what would have permanently solved the issue of the Danzig Corridor and contributed to security of both Poland and USSR.
Churchill was most likely interested in the weakening of Germany while Stalin saw this border change as a pretext to take hold of eastern Polish territory, inhabited by a substantial percentage of Ruthenian people (in the central part of Eastern Poland the percentage of people speaking Polish as a first language was usually less than 30%, and in some regions even as low as 5%), preferably all the land seized by USSR in 1939 thanks to Ribbentrop-Molotov pact, what more or less incidentally made it similar to the border proposed in 1919 by British Ministry of Foreign Affairs (commonly known as Curzon Line after the Minister, although it was not authored by him). Churchill generally agreed to this plan, pointing out that Poland will need to get a compensation in the form of the lands in west, preferably equal in territory to the lost eastern territory. In a final summary, Churchill, Stalin and Roosevelt made a preliminary agreement to USSR retaining the lands east of the 'Curzon Line' and the access to the non-freezing Baltic port while Poland was to get a recompense in a form of the southern part of Eastern Prussia and German territories east of Oder and Neisse rivers (now Pomerania, Greater Poland and Lower Silesia).
The decisions made in Tehran were largely confirmed during Yalta Conference and made official at the Potsdam Conference with some small amendments. Territory of Poland has been essentially shifted westwards, with the lands annexed by USSR in 1939 becoming part of Lithuanian, Belarussian and Ukrainian SSRs, although Poland regained the territory around Białystok (now Eastern part of Podlasian Voivodship) and Przemyśl (now southeastern corner of Subcarpathian Voivodship) and Poland being granted aforementioned German territories. In theory, the former German areas were to be only administered by Polish authorities until the next peace conference, but the one held in Potsdam was the last one, making that point inconsequential.
USSR-backed Provisional Government of the National Unity signed the bilateral agreement with USSR, agreeing to all the territorial changes and thus cementing the post-war shape of Poland. Although according to the international law PGNU was not a legitimate Polish government, British support for the decisions made in Tehran and Yalta essentially sidelined the Polish Government in Exile, accepting Poland as a part of the Soviet sphere of influence. Without any political backing, Government in Exile lost any influence over the post-war Poland.
The territorial changes in their final shape resulted caused Poland to lose 175.000 km^(2) (67.500 sq mi) in the East, while receiving about 100.000 km^(2) (38.600 sq mi) of the former German area, making it a significant territorial net loss. Former German territories were better developed that the chiefly agricultural areas in the east, but they were also ruined by the war. The border shift was also followed by the mass migrations. Polish inhabitants of the Central Poland and the areas lost to USSR as well as the Poles held in the Siberian internment camps (2.9, 1.5 mln and 0.5 mln respectively) were resettled to the new territories that were vacated by Germans fleeing during wartime and forced to resettle into post-war Germany (5 and 2.5 mln respectively). Roughly 1.5 million of the inhabitants of pre-war Poland remained in Soviet territory.
Thus, Poland received a part of the former German territory because of the decisions taken by the leaders of Great Britain, USA and USSR during Tehran, Yalta and Potsdam conferences who treated it as both a way to weaken Germany and a recompense for the Polish territorial losses to USSR.