Over 50% of those "living off the government" are pensioners, so mostly coming from a pool of people who already worked (and most of them in the private sector), and paid their share in taxes. In spain, the private sector makes 70% of the active workforce, while the public sector around 13%, self employed 13%, and unemployed 10%.
I know Spain (and Europe) have quite a lot of structural problems, but I fail to see how having so many pensioners has anything to do with AI regulations.
Its even worse in the UK where we have a special additional income tax (NI) on earned income (things like investment income are exempt), that is higher on people with low to moderate incomes, that is primarily used to pay (current) pensions (a little bit is set aside for future pensions, but there is only enough set aside for less an an year of payments).
The important part is how large fraction of the population work, not where the money for the remaining fraction comes from. Money is only a representation of value, value created by the working fraction.
Setting aside money, and where you put it, makes a big difference. It might be in a sovereign wealth fund, or used to finance govt debt (as in the small fund that exists in the UK) or invested in shares by a private pension fund, or be a liability of a past employer. In some of those cases value might be generated in another country.
You are right in principle but there are big practical differences too.