No magic is needed. In a world where everything is free software, almost no spyware would happen. And the "almost" is because nobody can watch everything every time. But the most used software will be thoroughly reviewed.
But we don’t live in that world yet. We live in a world where, on the contrary, companies are able to make products that distribute their spyware and do so by actively exploiting the contributions of free software developers! The Linux devs whose contributions are in android are having their software used to build TVs that spy on people! Is free software advocacy alone actually helping advance a spyware-free world, then?
No, the eventual goal of the FSF (and Stallman himself) is to make all software free. You cannot achieve this goal at once, you need to make part of the software free first.