Yes, that's how nations work. Otherwise you end up paying for the world's social security while not collecting everyone's taxes.
https://www.swissinfo.ch/eng/swiss-politics/swiss-warn-eu-jo...
This thread is about migration and residence, not benefits.