Because the technology to send a spacecraft to another planet is the same technology to solve terrestrial problems.
The Internet, nominally the single biggest technology solution for the developing world ever, runs on compression and error correction algorithms that were first implemented for Voyager.
A manned mission to Mars must solve a the problem of a closed ecosystem. Think that might be important to developing countries who are polluting terribly (just like everybody did) in an effort to modernize?
You can't solve everything. There will always be some problems.
And, get enough good scientists together and those same scientists will start demanding that you make progress on domestic fronts as well.