The Cold War helped drive the space race from both sides seeking political and technological advantage over the other. Neither country wanted to be seen as coming in second place in scientific exploration, and both sides were keenly aware of the potential intelligence and strategic advantages space dominance could provide.
Before manned spaceflight, the primary goal of space exploration was espionage. Satellites could provide intelligence about the enemy while remaining high enough to avoid interception or destruction. The United States had an active satellite program before Sputnik, but kicked it into high gear once the Soviets orbited their first craft.
Early manned missions took advantage of the Cold War by reusing Air Force ballistic missiles as launch vehicles. The first Mercury missions used modified Redstone surface-to-surface missiles, while later launches used Atlas intercontinental ballistic missiles. Project Gemini used the Titan II ICBM, and these launches doubled as propaganda vehicles to show the Soviets the capability of the U.S. missile arsenal.
Ultimately, NASA's goal for putting a man on the moon grew out of the U.S.-Soviet rivalry. By the early 1960s, the Soviets had significant advantages in heavy lift capability, and their experience in orbit made it difficult for the United States to catch up. Only by leapfrogging ahead to the moon could America balance the scales and ultimately win the race.