The people of Korea have for hundreds of years been subjugated and ruled over by the Japanese Empire before World War 2, so when Japan lost in the World War, there was no nation to reinstate in Korea. Korea was divided into two, America and USSR by the allies to govern until Korea will create a unified government of its own. The south was governed by America democratically and with a capitalist system, while North Korea was governed by USSR using a dictator with a communist system, so the two sides couldn’t agree on which political and economic system is better resulting in the country never unifying peacefully.
The split of Korea between North and South created two governments that are ideologically and territorially divided, and will never agree to compromise. North Korea saw that there will never be a peaceful unification of Korea, which will result in a communist Korea, so they invaded South Korea trying to make a United Communist Korea starting in June 1950.
The surprised invasion caught South Korea off-guard, so the North Koreans successfully beat and surrounded South Korea’s army in a few months into a small corner in Southeast Korea. The United Nations condemned the invasion as illegal, so the UN send an international army to help South Korea, which mostly comprised America because of America’s strength and enemy of communism. The UN army swept North Korea’s army almost to the brink of total surrender to the border of China.
China also a communist felt threatened by the capitalist army and also a communist itself came with a gigantic army that swept the tide helping North Korea to gain all the lands it once had before the Civil War where the UN and South Korean forces and the Chinese and North Korean forces were gridlocked where there were several skirmishes and small land exchanges, but nothing major.
At last, in July 1953 South and North Korea signed an Armistice that ended all hostilities and established the border on the 38th parallel the same border that was before the Civil war. The war never officially finished because the two sides only signed an Armistice, not an official peace treaty.