The Korean war was not a simple issue. It arose both out of World War 2 and the rapidly developing cold war. Since Korea had been occupied by Japan since the early 1900s, it was obvious that the victorious Allies would occupy it for a time following the defeat of Japan. The U.S. and the Soviet Union made an agreement to divide the Korean peninsula, without taking into account the possible wishes of the Korean people-- The Russians would be allowed to occupy the territory only as far south as the 38th parallel, and the U.S. would occupy from Pusan to the 38th parallel. Neither nation understood or cared that national independence and a unified nation were primary political goals of the Korean people. After occupation, the Russians supported a communist regieme in the north, arming it heavily. On the other hand, the U.S. paid little real attention to Korea, being primarily interested in recovering from WW2 rather than taking on new tasks. Initially, the US had nearly 50,000 troops occupying their zone of Korea, but soon, in the throes of postwar drawdown, reduced those forces to less than 500. US forces in Japan were also drawn down, and were allowed to stagnate and become combat ineffective, with poor manning, obsolete weaponry, and almost no training. The story of the postwar political situation is complex, but essentially, the US tried to let the United Nations solve the problem of reunification. The UN determined there would be nationwide elections in Korea, but the Russians and their allies in the North refused to participate. Communists in South Korea refused to vote, boycotting the election, and no vote was permitted in North Korea. Sigmon Rhee, a conservative nationalist, was elected in the South, and became President of South Korea. The Russians installed Kim Il Song as the ruler of North Korea.
South Korea was not heavily armed by the Americans, while North Korea was given large quantities of heavy weapons, with large armored forces.
The US continued to believe in containment of Communism, but decided that such containment could be economic and political, with limited requirements for US military force-- economic and military aid was to be given to non-communist nations in Asia. The Chinese Communists took over China. In early 1950, Dean Acheson described this new American policy. He stated that the US would militarily defend Japan, the Philippines and the Rykus. He did not mention Korea. As the US withdrew its forces from South Korea, The North Koreans became convinced that the US would not intervene to protect South Korea from a North Korean attack. In June 1950, Kim il Song, with the political (and later military) support of the Russians and the Chinese, attacked across the 38th parallel.
I consider the best work on the events leading to the Korean War to be T.R. Fehrenbach, “This Kind of War”. I think you will find it a fascinating read. In his summation, he notes that the ultimate cause of the Korean war was that “it was allowed to happen”, when it could have easily been prevented by a different US policy.
The Korean War was a result of internal turmoil and external forces. Internally, the big issues were:
Externally, the issues were:
On it's face, the Korean War was about the North invading the South to reunite the country under Pyonyang's rule. What made them think this was possible? On June 15, 1950:
North and South Korea had been separate, independent countries for almost two years (September and August of 1948, respectively). During that time, the Republic of China government had fallen and Beijing was in communist hands, Korean communist volunteers returned home with years of combat experience, and the Soviets had built up a sizeable military in North Korea. In the South, the opposite had occurred. Syngman Rhee was as anti-communist as Kim Il-sung was communist and had visions of building up his army and marching north to reunite the country. The US was fearful of this, not wanting a war with China or Russia, especially since the Soviets had developed their own atomic bomb in 1949 and the Cold War was in full swing. The southern military was a glorified police force using old surplus weapons. When Rhee would ask for lots of big guns, the US would send him a few small ones. The US was doing everything to prevent Rhee from unilaterally attacking the North.
In early 1950, Dean Acheson gave a speech where he laid out the "The [US] defensive perimeter runs along the Aleutians to Japan and then goes to the Ryukyus." Omitting Korea from the defense perimeter gave Kim the idea that the US would not get involved in a war in Korea and he was able to convince Mao and Stalin of that as well.
From 1945 until the foundation of the DPRK and the ROK, there was much internal strife on the Korean peninsula. First, the actual occupation of Korea was hasty and unplanned. The Allies had agreed at the Cairo conference (which Stalin, as a non-belligerent with Japan, did not attend) that Korea would be liberated from Japan. The idea was to place it in a trusteeship for an indeterminate amount of time. Roosevelt envisioned it lasting 50 years or more but with his death in April of 1945 those plans evaporated. At the Yalta conference, the Soviets agreed to enter the war 3 months after the defeat of Germany, which it did, on August 8 (August 9th in Asia), a few hours before the second atomic bombing at Nagasaki. With the complete collapse of Japan imminent, and the overwhelming military that the Soviets had built up in the Russian Far East, and the fact that the nearest US soldiers were on Guam or Okinawa, the Soviets were able to capture Korea single handedly. The moved so fast that the US had to propose a line of demarcation, the 38th parallel, which the Soviets accepted. The line was picked at random by two low level officers, future General Charles Bonesteel and Colonel (and future Secretary of State) Dean Rusk, who, upon learning it was the same line that the Russians and Japanese discussed during the Treaty of Portsmouth for their boundary of influence said "had I known that, I almost certainly would have picked a different line."
Second, with two spheres of influence on the peninsula, the provisional government in exile basically had to apply to the new masters for their old jobs. Rhee, the first president of the Provisional government, ended up being the man that the US pushed and supported. This is due, in no small part, to the fact that Rhee spent a lot of time in the US lobbying for Korean independence and had made a lot of powerful friends. At the same time, Kim Il-sung was installed in the north when Cho Man-sik, the more popular local leader, was removed by the Soviets when he wouldn't support trusteeship. Kim and Rhee were not the people's first choice, although Rhee would win the election in 1948. People like Cho, Kim Gu, Kim Tu-bong, and Kim Kyu-sik were more popular with the people, but they would all die at the hands of Rhee, Kim, or their surrogates.
These differences are highlighted by the backstories. The North Korean leadership consisted of two (main) factions, the Yanan and the guerillas. Kim and the guerillas openly fought the Japanese and had close ties to the Soviets, while the Yanan faction had joined the Chinese military and had ties to Mao. There were also groups of homegrown communists and Soviet Koreans, ethnic Koreans who had fled to Russia/USSR during the last 50-60 years and came back to the North after the Japanese were defeated. Kim and the Soviet faction were able to gain control and purge the Yanan faction in two big waves, in the late 40's and again in the late 50's. By then, Kim had become the undisputed leader.
Third, from the end of the Japanese colonial era until the Korean war, upwards of 10% of the North Korean population moved south. This especially included landowners and the educated. Landowners were persecuted by the North for their Japanese collaboration (both real and perceived) as well as for simply being rich parasites, living off of the working class for millennia. The south also had some Japanese collaboration witch hunting but many of those in power were the same ones who had collaborated and only around 600 cases were investigated resulting in less than 30 convictions. It wasn't until the last 20 years that collaborator investigations really began.
Externally, the biggest factor was China and American... stupidity? Arrogance? MacArthur?
The US had been supplying Chiang Kei-shek against the communists for years. Once they had won the Civil War, the communists were concerned about the US presence in Asia. The US was still supporting the ROC government and was protecting Formosa from invasion (which the communists couldn't have done even without the US Navy in the way. They lacked the ships or planes to make an attack possible), and they had a large presence in Japan, their (former) enemy's homeland, a short boat or plane ride away. Having been victims of imperialist aims before (Britain - Hong Kong, Portugal - Macau, Germany - Tsingtao, Japan - Manchuria, the Boxer Rebellion, the Opium Wars, etc) the Chinese wanted to ensure that the US wouldn't try anything. When Kim talked to Mao about the war, Mao's advisors cautioned against the war, fearing US nuclear weapons and planes. Mao was undeterred and was willing to risk atomic warfare for a chance to kick the US out of Asia and create a communist buffer state in Korea to keep Japan at bay.
Once the war began and the US got involved, the Chinese mentioned in a roundabout way that if the US/UN forces entered North Korea, that the Chinese would enter the war. MacArthur was aware of this and he played it off. They were posturing, they wouldn't do it, if they did come he could beat them easily, yada yada yada... By September, the Chinese had already begun mobilizing in anticipation and by the time the US forces crossed into North Korea, the Chinese were already gathering for the war.
What's all this mean
The peninsula was divided by foreign powers who had limited knowledge of the local political situation. The US was focused elsewhere (Europe) and didn't help the south build up a strong military and then it declared the south as outside of the US defense interest. The Soviets were NOT looking for a war but when Kim came calling and the Chinese offered to back them, the Soviets gave the go-ahead. What could have prevented the war? Assuming a divided peninsula...
TLDR
The causes were: