You must not mistreat or oppress the stranger in any way. Remember, you yourselves were once strangers in the land of Egypt. (Ex. 22: 21)You must not oppress strangers. You know what it feels like to be a stranger, for you yourselves were once strangers in the land of Egypt. (Ex. 23: 9)
It's a good point and it's interesting that the Torah's means of fighting this impulse is by appealing to our very same tribalism, telling us to identify with the stranger because we are alike. I'll just add that the Torah also makes use of our tribalistic instinct in other, more active ways.
As Haidt says "Morality Binds and Blinds", blinding us towards outsiders while binding us to our own group or caste. There are many mitzvot that build on this binding impulse, all the mitzvot that apply to אחיך. For example:
- The obligation to redeem him if he becomes a slave
- The obligation to redeem his land if he is forced to sell it
- The prohibition on hating him
The picture that emerges is that the Torah rejects our tendency to treat strangers unjustly, while at the same time building on our natural tendency to go beyond mere justice with our fellow Jew.