21 “Thou shalt neither vex a stranger, nor oppress him: for ye were strangers in the land of Egypt.”
Jesus said, "Do unto other as you would have them do unto you."
The Israeli people lived in Egypt for 400 years. They were not the original inhabitants of the land. They were immigrants, who came to Egypt for asylum from the drought that threatened them. Of course, Joseph being who he was greatly influenced their decision to stay.
The Egyptians thought it was an abomination to socialize with them because of their choice of occupation - herdsmen. Today, that would be like, for instance, a yuppie in our society thinking that all rednecks are dirty. Or, a white-collar worker looking down his nose at the McDonald's employee he just ordered his Big Mac from.
Of course, we could also expand that to the prejudice between blacks and whites in our society today. People tend to be offended by people who are "different", no matter what the societal nature is.
In this verse, God is telling us to treat immigrants with respect. This does not mean to allow them passage if they are not following the rules. This means only that you should treat righteous immigrants with respect and as a true neighbor and friend. After all, it wasn't that long ago that Israel was enduring such prejudice, and they didn't like it. Therefore, they shouldn't treat others in ways that offended them when they were being treated that way.
It is always wrong to discriminate, or to act on prejudice.