@JamesK and @DavidHammen answers are pretty good, but there is still another important aspectsaspect:
Space technology and military technology are pretty much interconnected.
By developing a space industry, a country can develop high-end rocketry and other military-important technology:
- for less money (like, say, 100x less without the military/secrecy/etc bonus)
- on pretty much market grounds (competition is good for everyone)
- without annoying their own pacifists (up to and including high-profile experts refusing to work on military projects).
- without annoying the hell out of their neighbouring countries
(Say to China that India develops ICBMs and look for the diplomatic fireworks. Say to China that India wants to land on Mars - well, China will think about ICBMs as well, but will just say "we already did, good luck getting there sec... oh well, fourth".)