> if they want to be xenophobic, what's the problem?
One of the problems is that even if the majority of people within a country are xenophobic and they get to decide the lays on a majority basis, there will still be people form other countries living there, or people who in general will be disadvantaged by xenophobic laws.
It's nice for laws to not be dictated only by a majority, but by a plurality. Instead of thinking "what benefits >50% of people is the right thing" we can think "what benefits the most people, including minorities", or "what avoids hurting the most people" to be the right things :)
Creating laws based on popularity makes populism rule. Hence why democracy usually has an explicit legislative branch abstracting over individual sentiments. That helps prevent policy from being devised through an overly greedy algorithm.
That is not to say it prevents all these problems. But it evidently helps.