Scriptural Analysis- Exodus 23:9

9 Also thou shalt not oppress a stranger: for ye know the heart of a stranger, seeing ye were strangers in the land of Egypt.

God had already commanded the Israelites not to vex or oppress any foreigner living among them, but now He repeats that directive a second time, and once again the reason given is that the Israelites had themselves been strangers in a strange land, and so they knew the heart of those that lived such a life.

This is an interesting logic, a sort of divine paradox, to say that because the Israelites were themselves oppressed when they were the foreigners, that they therefore must not oppress any foreigners themselves. Our human tendency is far more inclined towards “since you did it to me, I get to do it to you.”

Recall that when Israel departed Egypt a mixed multitude went up with them, which means foreigners in their midst. These may have been other slave nations that had served under Egypt, but it may also have been some of the Egyptians themselves. Furthermore, after they entered the Promised Land some immigrants of their own enemies would come live among them, such as Ruth who came from Moab. Thus, when God says to not oppress the stranger, He is including strangers that came from lands that were directly hostile to Israel. It would be absolutely natural to let their anger against those enemies loose upon the immigrants that came from them, but God required His people to take the higher road, to return kindness for offense.