That way, everybody is taxed fairly - proportionally to how much they earn and consume. So, everybody should also be treated fairly - provided all the basic services that the government provides.
The small, rich countries in the north have a lot less problems with controlling immigration, owing to cold or wet borders, low absolute population and low population density. These countries only recently became attractive to immigrants. They may even be able to deport most of the illegal immigrants.
Germany for example can't expulse illegal immigrants on a grant scale. Justified public outrage about "German mass deportations" would even be the least of problems. It's just logistically and politically impossible.
That's why I say that immigration is almost impossible to regulate effectively with the means available to a democratic nation. You'd need some kind of STASI to hunt down hundreds of thousands of immigrants. Nothing would be worth that....
In the US, undocumented immigrants have that problem though. Some politicians praised illegal immigration because that's a young, eager workforce with zero rights and benefits.
Also it seems that welfare states can't really save money by excluding immigrants. At the very least the society has to foot the bill for medical emergencies, so declining them prevention and health care may fire backwards. It's hard to "get rid" of the immigrants' children, so you better make sure they get the same education and chances as citizens do (or you end up with a young, poor and extremely discontent minority). If these children aren't put in good schools and fed accordingly, they will also be sicker and less intelligent than their peers.
That's why I think social security is a very profitable business for state and society.