They lost because of an inability or an unwillingness to adapt to the changing environment on the battlefield.
Personally, I think in each case it was more of an example of "biting off more then they could chew".
Now Germany's single biggest mistake was declaring war against the US, and right behind that was declaring war against the Soviet Union. They had sound tactics, good equipment and superbly trained soldiers. But against the 2 largest industrialized nations in the world at once, they never had a chance.
For Japan, it was relying to much on their superiority in all things, and over-reaching their goals. First they harassed the US for a decade prior to the war, then started an unneeded war with a sneak attack against the largest industrialized nation on the planet.
But both sides clearly showed that they could adapt to battlefield conditions, and change as rapidly if not more so.
For a clear example of this, look at the behavior of the Japanese.
At the start of the US Offensive in 1943, the tactic was to meet and fight the US with everything they had on the beach. Bloody Tarawa ended in the almost total destruction of Japanese forces (17 survivors out of almost 4,700 soldiers), and killing less then 1,700 Marines.
A year later, they had learned a lot and changed. The Battle of Iwo Jima lasted for over a month, and they primarily fought from hidden dug-in positions. Of over 22,000 defending on the island, just over 200 survived. And US forces were hit much harder, almost 7,000 killed and 20,000 wounded.
And Okinawa was even worse. If they had not learned and adapted most of the Pacific Campaign would have been a cakewalk. And in many ways, they and the Germans were ahead of the Allied forces. Just look at the Panzerfaust and the Type 89 Grenade Launcher (commonly called the "Knee Mortar").
In fact, I have long believed that the Japanese had the finest Hand Grenade system in the world, then or now.