Although we say that the legitimacy of governments comes from a democratic electoral mandate, I don't believe it. I believe it comes from a government delivering ever-increasing standards of living. In somewhere like China, you can overlook the lack of democracy if your parents grew up fearing famine and you know that your children will never go hungry.
Here in the UK, we've got used to the idea that everything is getting better all the time. Unfortunately, for a substantial proportion of the population this had little connection with individuals' own productivity, but was the result of wealth redistribution. What has changed enormously in the last two or three decades is expectation and the cost of meeting it: in the 80's a Ford Sierra was seen as a big expensive car and McDonalds was a treat for the kids. Now, a BMW 3-series and eating out at a decent restaurant once a week mark you down as distinctly average.
The ability of government to allow everyone to enjoy at least some of those expectations has reached the end-point. It simply cannot be done at a level of taxation that the public is prepared to support, or at the level of public borrowing that gilts buyers are prepared to support so the can cannot be kicked down the road any longer. With public finances stretched to the absolute limit something has to give; "cuts" are the inevitable consequence.
At the same time, with no wriggle room left in public finances for a rainy day the slightest shock causes a full-on crisis. We saw it in 2008, and we're seeing it again with Brexit. Heaven forbid what happens with AI, automation, and the rest putting half the worforce out of work.
The hostility comes from proportioning blame for the dawning reality that for years as a nation we have lived far beyond our means. Foreigners and foreign influences are an easy target, always have been, but the evidence doesn't back it up. It is the average man in the street who been complicit in the lie that the nation can still afford an unfunded state pension scheme, an unlimited NHS, various in-work benefits, housing for poor people in some of the most expensive real estate in the world and so on, at a price that we're prepared to pay in tax.
Attempts to privatise state spending - for example by expecting rail users to pay for the cost of the railways, or for university students to pay most of the cost of their education - are still being resisted.
It's not hostility towards natives by design, in my opinion (I'm foreign too, but that's a different matter). But the day of reckoning about the standards of living we can afford is getting closer, and the febrile atmosphere is because nobody wants to admit it.