Can only speak for the U.S., although I suspect it most likely is part of the explanation in other countries as well.
We are a nation built on immigrant labor, which we historically take pride in. My great-grandparents were typical. They immigrated from Baden when it was still sort of an international city, and the U.S. actually maintained an Immigration Office there recruiting European immigrants. My great-grandfather was fleeing conscription into one side or the other in the Franco-Prussian War (Baden could have swung either way).
Yet reality is that every wave of immigration--Irish, German, Scandinavian, Italian, Latin-America, ad infinitum--has generated a political backlash with horror stories about them taking our jobs and being an influx of murderers, rapists, criminals. It is the type of demagoguery that certain authoritarian type politicians thrive upon, going back to Federalist times, through the Know Nothing Party, the America First isolationists, McCarthyism, or the current MAGA movement.
Meanwhile, certain labor-intensive industries -- agribusiness, construction, hospitality, for example -- need workers willing to do manual labor at relatively low wages that U.S. citizens find beneath them. Concurrently our educational system has gone in the dumpster, with university educations being priced so high and tied to a ludicrous student loan program that leaves you paying off high interest rates the rest of your life. And at the same time, the public community college and trade school system was gutted and turned over to for-profit chains milking the student loan program. So we have a dumbing of America at the same time more and more jobs are requiring educated, highly skilled workers. The solution was simple: follow the same path as the labor intensive industries and recruit workers from countries where education is still valued and made available to many.
And of course the oligarchs are able to get ICE to look the other way when it comes to making sure corporate America checks on immigration status, green cards, etc. It is all the "illegals" fault, and the lack of border enforcement (on only one border).
Our immigration laws have been out of synch with reality for at least a half-century and every bi-partisan -- or even single-party -- attempt to fix them has been met with a hail of "No amnesty!", "they broke laws and are therefore illegal" without ever coming to grips with the fact that immigration law has been broken for a long, long time and like any broken, dysfunctional law, people ignore it. Immigrants, employers, corporations, oligarchs, all treat it as a "scoff law" because it is so out of date.
But they provide grist for those who rely on simple answers to complex issues and finding some group which looks and/or talks differently, was raised in a different culture, and can place all the blame on them.