This is a really comprehensive question, and one that entire careers have been founded on. Put ten historians in a room and all ten of them will have somewhat differing explanations. However, the Nazi failure in WW2 is inextricable from the irrationality of the National Socialist project. 'Destruction of racial enemies' is not a strategic aim that is easy to pursue with the normal calculus of war, and this is plainly observed in the campaign against the Soviet Union. The invasion of the USSR was predicated explicitly on the supposed existential threat of 'Judeo-Bolshevism' to the German nation. As a result, the war aims of the invasion were to establish a line of control running north-south from Arkhangelsk to Astrakhan, nearly a thousand miles from the German line of departure. This was seen as 'necessary' because it would prevent Soviet bombers from reaching Germany proper, but more importantly because it would allow the Germans to conquer the vast and fertile farmland of Ukraine, Belarus, and Western Russia. This farmland would play host to a 'national rejuvenation' of the German people, in the form of providing space for German peasant farmers - this is the whole Lebensraum concept at work. The Slavic peasants living here would, of course, be removed by merciless ethnic cleansing. This is a point I want to emphasize, because it often gets lost in the traditional narrative of the "Ostfront". The traditional Cold War Anglo-American narrative was built for many decades on largely German military experiences & interpretations - this is why for some reason it is often referred to as the "Ostfront" or "Eastern Front" - and it was built largely by the American military establishment. This yields two uncomfortable facts: one, the criminality of the Wehrmacht is downplayed in this narrative, and two, when war crimes do enter the narrative they are a sideshow to the "important" part of the narrative, the battles and the operational maps. However, to understand the Nazi invasion of Eastern Europe, we really have to understand it as a war of ethnic extermination first and foremost, rather than a regular war with war crimes on the side. The clearing of Slavic lands for settlement by German peasants was not a side effect or a secondary consequence of the invasion: it was the primary reason for the invasion. It could only be achieved by military means of startlingly optimistic thinking, and the degree of success that the Nazis enjoyed in the first 18 months of the campaign is frankly one of the 'luckiest' military successes I can think of. Many things went right for the Wehrmacht that were not predestined to go right, including things the Wehrmacht had not planned on going right.
I've written more recently here as well: https://www.reddit.com/r/AskHistorians/comments/gcs22s/why_did_barbarossa_falter_and_fail/fq4ut7s/?context=3
For the general aims of the invasion of the Soviet Union, Chapters 6, 14, and 16 of Adam Tooze's Wages of Destruction are illuminating, as is Evan Mawdsley's summary in Chapter 1 of Thunder in the East. Pete Kakel's The American West and the Nazi East: A Comparative and Interpretive Perspective is also worth reading.