Although it is difficult to recreate the mindset in 1950, at that time the United States feared the Soviet Union would start World War III in a bid for global domination. The U.S. had just five years ago emerged from a very costly and destructive world war started by a regime with global domination on it mind, so naturally was still jumpy. Furthermore, in hindsight, people realized that if Hitler had been contained early, a world war might have been avoided. The U.S. was not going to make the mistake again of waiting too long to intervene.
So a chief goal of the U.S. was to avoid World War III by pushing back hard against what it understood as Soviet aggression. It wanted to discourage the USSR from expanding its empire—even if this meant going into a country quite remote from the U.S.
A more direct goal of the Korean war (the war was officially called a "police action") was to protect Japan, which the U.S. considered its linchpin to stability in Asia. Korea was too close to Japan for comfort, and the U.S. feared that a Korea unified as a satellite state of the Soviets could too easily try to invade Japan.
More specifically, the U.S. was determined to push the North Koreans back above the 38th parallel, the dividing line between North and South Korea, and keep them there. The goal was to nip communist expansion in the bud before it could grow into a monster that could only be contained by a major war.