Why was the United States' national security threatened during the Korean War?
Technically, US national security wasn't threatened by North Korea's invasion of South Korea in 1950, but US involvement was not unwarranted.
After Japan surrendered control of the Korean Peninsula under terms of its surrender to the USA, the peninsula was split into a Northern portion occupied by the Soviet Union, and a Southern portion initially occupied by the US. By 1950, the US presence had diminished and been replaced by a force of member nations of the newly formed UN that was mainly focused on helping the Capitalist government in the South remain stable while negotiating with the Soviet influenced dictatorship in the North for terms of unification. The invasion in 1950, was technically an act of war against the UN, and was only against the USA insofar as US forces made up part of the UN force.
The other reason for the US to act was Japan. In its post-war constitution, the Japanese almost completely foreswore military power. The constitution allowed for a "Coast Guard" due to the nation being made of islands, a small token "army" (more a national police force), and no provisions for air power. As a bulwark against this vulnerability, Japan became an ally of the USA in the brewing Cold War, and thus obtained US protection of its sovereignty. Unification of Korea under a Soviet-backed Communist regime would pose a dangerous threat to nearby Japan, especially with the communist neighbors of the USSR, and Red China. The USA, as Japan's chief defender, could not allow this to happen, so had to maintain a US/Japan friendly South Korea.
While it is possible to argue that the United States’ national security was not threatened by the Korean War, it is also possible to argue that it was. To argue that it was, we need to take a very expansive view of what America’s security was. Specifically, we need to argue that any expansion of communism was a threat to the national security of the US.
If this was the case, it was because of the domino theory. This theory held that any expansion by communism would lead to further expansion. If one country became communist, it would cause the next country over to become communist, just as a falling domino can knock over the domino next to it. By this theory, a communist South Korea could have led to communism taking over Japan. This might have endangered Taiwan and the Philippines. Soon, the US would be deprived of all its allies in the Western Pacific. This would have made the US isolated and vulnerable.
In this way, the Korean War was arguably important for America’s national security.