I looked this up but i can't find a satisfying answer. Considering the enormous tension from cold war and the giant stockpiles of nukes, it could have ended really badly. What was there to gain from Korea that justified risking the end of the world to get it?
I indirectly answered this in my discussion on the dynamic Tibet played to the Cold War in the 1950s.
Essentially: Stalin was probing for weaknesses in the West's defenses. Berlin and Greece were secure, and the Maoists had just won their civil war against the Nationalist government. So while Europe seemed like it was locked down barring nuclear war, Asia seemed like the weakspot of the Western Democracies.
For the United States, it was less about what they could gain from the territory itself, and far more about Truman's "Containment" policy, i.e. keeping Communism in check where it was and not allowing it to expand.
From what I understand the Russians/chinese decided to invade Korea for total takeover of communism. From the onset of the cold war, this was hugely important to prevent. Enough lives had already been lost and Korea was basically at risk of being turned into a total totalitarian state with no democratic potential/liberty for its people. America intervened to stop this because they're one of the only superpowers large enough to do so and to prevent communist propaganda. Invaded South Korea and made a pact for the 38th parallel with Stalin. Korea has alot of natural resources, it's location is important geographically, between the Asia Pacific and China, can be useful for gaining political/economic leverage especially against foreign governments, maybe even staging coups. Hope this is helpful?