There were many steps that helped to cause the Korean War to occur.
If you want to go far enough back, you could argue that the Bolshevik Revolution in Russia in 1917 was a major cause of the war. It allowed communism to come to dominate what had been Russia. This led to a situation where, decades later, North Korea was communist.
The next big step was WWII. For decades before the war, Korea had been a Japanese colony. At the end of the war, the Soviet Union invaded Korea from the North. The US occupied the South. This set up a situation in which Korea was split into two countries, a communist North and a non-communist South.
The next step was the victory of the Chinese communists in their civil war. This put a communist country on the border of North Korea. It also provided support to the North Koreans as they planned to invade the South.
A final step before the invasion was a speech by Dean Acheson, US Secretary of State, in early 1950. In that speech, he seemed to put Korea outside of a sphere that he said the US would defend. This emboldened the North to think that the US would allow the invasion to stand.
Finally, there was the invasion of South Korea by the North that started the war.