The state pensions these days are tied to where you worked and paid taxes. At least that's the case in Denmark (not as familiar with Sweden). If you work in Denmark 40 years, you're entitled to a full state pension. If you work 20, you're entitled to half of one. If you work 4, you're entitled to 10%. You don't get it solely by citizenship. There is some basic welfare support for those who live in the country, though, e.g. if you're a Danish citizen who lived abroad and ends up back in Denmark dirt poor aged 70 and lacking a pension from elsewhere to support yourself, you won't be on the street. But that is relatively uncommon.
Generally so far it hasn't been a major issue, though things are being continually tweaked, and there are some tax shenanigans especially at the corporate level. But Scandinavia has been fairly successful in the inter-country competition for being seen as a nice place to live. It's pretty uncommon for people who study at university here to pursue careers elsewhere for more than a short period of time, because most Scandinavians prefer to live somewhere with a functioning civil society and government, low levels of crime, good support for raising children, and generally a working social system.