But let us remember those words of von Clausewitz: "War is a mere continuation of politics with other means" ("Der Krieg ist eine bloße Fortsetzung der Politik mit anderen Mitteln"). War cannot be justified without its political objectives, otherwise it'd just be killing people for the sake of killing people.
I second Lizardo's observation that the bombs prevented the Japanese from surrendering to the Soviets. Also I find it mindboggling that there seems to be some equivocation of Allied to Axis in this thread. A victorious Nazi Germany would be one to continue its policies of slave labour, its continued subjugation of Russians and the final (literally) extermination of the Jews in Europe. A victorious Japan would mean the continued subjugation of China and South East Asia. It's not like America coming out on top and being a major superpower for decades was exactly good for the world as a whole but the alternative seems a whole lot worse.
Military decisions are never simple because they involve managing political realities which are always complex. And decisions are never made in a vacuum, you have to compare them to alternatives. Oftentimes war and politics are about choosing the bad over the worse situation.
Also, @Stormbringer: Hiroshima was an Army depot (meaning supplies, whether lethal or non-lethal), as well as a port of embarkation (meaning cargo is shipped to and from this port, ie not your port in Bumsville which docks maybe a personal yacht), as well as the site of a major military headquarters. Nagasaki was another major port and was the site of an urban industrial area that built almost every type of supply for the war effort. They were actually considering bombing Kyoto instead of Nagasaki, but changed their minds at the last minute (I think probably because Kyoto is just too culturally significant to Japan and nuking it would be wiping millenia worth of wealth of Japanese culture). Calling them "two cities that had very little or no strategic or military value as targets" is just simply untrue.
And despite the Japanese Empire being on its knees in term of conventional fighting ability, that didn't stop its high command from planning Operation Ketsugo (
https://en.wikipedia.org/wiki/Operation_Downfall#Operation_Ketsug.C5.8D) which would be their plan for resisting the American invasion. They believed that they could force an armistice by making an American invasion unbearably bloody and costly. In other words, they felt like the could get away without having to surrender to the allies, and counter to your assessment that a surrender was inevitable.
Also also also, please anyone reading this thread please do not leave it with the idea that the bombs somehow "led" to the Cold War, because that is a very misleading characterization of things. If you want to talk about the underlying forces at play, then you would have to consider as the most significance force a global order dominated by two, otherwise unmatched, ideologically opposed superpowers. If you want to talk about more proximate events, the Iron Curtain definitely has to be more significant than the bombs. And if you want to talk about the Cold War in Asia, then you should consider the division of Korea, as well as the de-colonization/liberation of Vietnam from the French to be much more significant.
tl;dr real life politics is 99% about bad vs. worse. also consider global geopolitical context instead of just thinking about how horrific the bombs were, because yes they were horrific, but yes there were horrific-er alternatives.