Example: Steve Fields
The best example of such a character that I can think of is Steve Fields (played by Michael Harney) in Deadwood. Steve is a town drunk with anger issues and ingrained racist behavior (which he spouts off plenty of times). He doesn't mean to be evil but he's practically uncontrollable and incredibly volatile.
He's painted as a chaos element who the main characters do not want to interact with and pretty much avoid at all costs (other than when he's paying for drinks). He is loud, brash, unnecessarily combative, and a general nuisance. And yet I sympathized with him at the end of his story arc. How did I get to the point of sympathizing with a loudmouth racist and xenophobe? Because I could see it from his side.
There is a stable in town which is owned by two black people. At one point, one of their horses runs wild and runs over (and kills) a child. Steve witnessed it, tried to stop it from happening and tried to tend to the child afterwards.
The stable owners, knowing full well that their skin color is not working in their favor and thinking it's likely they will get lynched, leave town immediately.
Steve has a bit of a soft heart and takes pity on the horses that are now left behind. He takes up residence in the stables and tends to the horses. This also gives him a purpose and while he's still a difficult man, his life and character dramatically improves.
Many episodes later, the stable owners return and try to kick Steve out, since it's their property. This is where Steve the racist xenophobe flies off the handle and we encounter a situation where it's hard to pick a side on who's wrong and who's right.
Steve is a massive racist but he did tend to the child and the horses without expecting anything in return. The stable owners are unfairly subjected to racism, but on the other hand they did avoid all responsibility in the death of a child that they pretty much singlehandedly caused.
The problem is Steve's character (and educational level), and how he expresses himself. He screams at the top of his lungs and gets in the face of and threatens anyone who thinks he's wrong. He doesn't argue the point of fairness, or his good intentions. He doesn't argue that he's de facto taken care of the stable for a long period after it was abandoned. Steve relies on what he knows: the alleged inferiority of black people. And his argument is almost purely one of prejudice and racial bias.
But the viewer knows that Steve is a simpleton who's struggling to express himself, rather than someone who's actively trying to make a racial argument for their own benefit. Over the course of several seasons/episodes, we have seen Steve and how his lack of manners works both in his benefit and to his detriment. This clues the viewer in that Steve isn't pushing an agenda, but rather that this is who Steve is.
Above all else, the viewer understands that Steve's argument is not just based on a blind belief, but rather a misinterpretation of the things that do actually happen to him. Steve has been wronged. The people who are wronging him happen to be black. Those are two objectively correct facts, but Steve's mistake is thinking that the two are somehow related.
In general
So how can you create a xenophobic situation where the xenophobe is understood as non-evil?
In essence, this is no different from an alleged evil character who turns out to be misunderstood (this is a very common trope for plot villains and monsters), or a good character who gradually becomes the villain (e.g. Harvey Dent => Two-Face).
You have to approach the conflict (at least one of the perspectives) from an angle that completely omits the xenophobic element. Show us the person, not their political ideology.
Don't start from their xenophobia and work your way out, because the reader will think of the character as "the xenophobe" and won't bother much with understanding the finer points of their character.
Instead, show us their character, and only reveal the xenophobic element when the reader is capable of understanding why the character does what they do.
- Show me a parent who is trying to feed their children, but struggles to find work to make the money they need.
- Then show me that the work he is capable of is commonly taken by immigrants who are cheaper. Be subtle about it, or at least don't let the character get caught up on their ethnicity for now (even if the rest of the world does)
- Now let this parent choose to get involved with a xenophobic (e.g. political or criminal) association that works to remove immigrants.
By taking this route, you've already laid the groundwork for the human element (feeding your children) to justify the character's choice (getting rid of immigrants).
Readers, just like all people (including xenophobes), are prone to prejudice. And first impressions matter. When a character is immediately presented as a xenophobe, readers will succumb to their prejudices just like the xenophobe succumbs to his prejudices.
Counteract that by showing us that they are humans with human emotions, an understandable life situation, and a justifiable need to look out for themselves. And then let those elements manifest themselves as (reasonably tempered) xenophobia.
From that point on, you can shape the events in that character's life that (coincidentally or not) reinforce their xenophobic ideals.