Deuteronomy 1:16 (ESV)

16 And I charged your judges at that time, ‘Hear the cases between your brothers, and judge righteously between a man and his brother or the alien who is with him.

Moses charged the judges (probably the commanders of the previous verse) to make righteous judgments, not only for full Israelites but also for the resident alien. The people of Israel knew what it was to be resident aliens, and the bitter experience they had as such; they were therefore not to treat their own aliens as they themselves were in Egypt.