The reason the are great economic powers after WW2 is the same reason they were great economic powers (or growing powers) before WW2 and all the way back into the late 19th century.
The goal of the allies was not the destruction of Germany or Japan as nations or of their economy. This leads to these nations going back to concentrating on peaceful activity. There nations are no longer obsessed with bad economic ideas, such trying to conquer large parts of the world to secure access to resources. Because they are dominated by the allies, the do not even have the option of such ideas.
Both Japan and Germany are modern nation states with a society and institution that have the means to facility all the factors needed for economic growth and they were set in a international situation that was very favorable to trade and investment. I don't want to go into to deep into economic theory, but if you are interested in theories of economic growth and development economics I can provide resources.
Rebuilding houses and infrastructures is far, far easier then building institutions (rule of law, local government and so on). This is why after WW2 Japan and Germany can easily be helped up and then keep running again, while such things or not so simple in other countries like and why these countries are bad arguments in support of 'exporting democracy' foreign policy, specially in relation to failed or nearly failed states (Iraq, Vietnam and many others).
Let me spend some time on what I think are bad explanations. Specifically the Marshall Plan and other polices such as debt reduction. These polices were great for the economy, however they can not explain good economic growth that is continuing to this day. The case for debt restructuring is far better then the arguments for the Marshall Plan.
Debt restructuring did not only help economically, but also in terms of international politics. West Germany would have had a extremely hard time paying back all the debt of Inter War Germany plus all the Reparations. I believe the could have done so, eventually, but they would still be paying them back now, and would continue to do so for a while. This would have some impact on growth but it could not have changed the generally positive growth that emerged from the post WW2 order.
Sources:
I don't have specific books about Japan or Germany. My reading is mostly more general economics and Germany, Japan and other are often used as example in these books. One example of (short) book that goes into this a little:
After War: The Political Economy of Exporting Democracy
/u/cahamarca and I wrote a great deal about how the Japanese economy underwent huge amounts of growth that propelled them into the top rankings of global economies in this thread quite a long time ago.
To summarize, it was a combination of the existing efforts of modernization and education that occurred pre-World War II that already poised Japan to quickly mechanize and modernize their workforce as well as streamline their education to prepare the children with modern skillsets that allowed them to excel in the global economy post-World War II.
Japan did indeed suffer a great deal of damage, especially property damage from bombings, were on the verge of starving, and were even subject to de-industrialization as part of the US Occupation (it was a part of the initial plan to prevent Japan from becoming a threat to the US again and went hand in hand with demilitarization [this would later be halted in the big policy change generally known as the Reverse Course, where the US redefined its policy goals in Japan within the greater context of containing Communism, causing a reversal in many policies, particularly repealing liberal and social freedom policies])
But, beyond food aid to prevent large swathes of Japan from starving, direct monetary reconstruction aid from the US was not that big of a factor in Japan's recovery, nor was it a major part in Japan's later economic boom. In fact, Japan only received aid for a few years and very quickly paid back their aid.
More directly, Japan's post war economic boom was heavily fueled by 3 major things:
1) US security agreement
Not having to spend billions every year on military expenditure freed the Japanese government up to spend that money in infrastructure, education, healthcare, etc.
2) Favorable trade deals with the US, and later other developed nations fueling industrial/ technological trade which further led to the growth of a massive services economy
While today, many know Japan as a place to buy reliable high tech goods, nice cars, and household appliances of every kind, in the past it was not so. Japan's manufactured goods back in the 50s and 60s was very poor. Labels with "Made in Japan" were treated with the same kind of ridicule "Made in China" often got in the 90s and 2000s.
The US allowed Japan a great deal for trading which gave Japan a foothold in a major market to sell their goods. This allowed them to expand and improve.
Japan overcame this initial reputation and was soon a trade partner everyone wanted.
3) The Korean and Vietnam War were essential boosts to the Japanese economy
War often brings many opportunities for profit, especially if your country/company is the one selling, not buying provisions for war.
The coalition, particularly US forces, relied heavily on Japan to help supply the expeditionary campaigns in East Asia and Japan experienced incredible growth. Japan's material and logistical support also helped the American PR campaign of turning Japan from wartime enemy into Cold War ally, which of course, helped sell Japanese goods in the American market.
Bottom line is Japan didn't simply become a global economic power because America gave it money
Japan didn't grow into a top 3 world economy because America funneled money into the country. If only it were so simple to build up a country.
So were equal amounts of money spent on European countries?