The Israelites were warned that they should eliminate non-Israelites from the Promised Land. (See, for example, Deuteronomy 31:3-6) However, this was not an absolute command. Most likely, those warnings were really against the false gods of these non-Israelites. Rahab, from Jericho, and Ruth, from Moab, were ancestors of David (and of Christ). They were both non-Israelite followers of God. Uriah the Hittite, Bathsheba’s first husband, who lived in Jerusalem, and was part of David’s army, had Canaanite ancestry, and he seems to have also been a follower of God (2 Samuel 11). David placed the Ark into the care of Obed-Edom, the Gittite (2 Samuel 6:10-12). Some bible scholars believe that he was descended from the Philistines from Gath, where Goliath came from, but others believe that “Gittite” has another meaning in this case.
The passages below give further evidence that non-Israelites were allowed to live in the Promised Land.
Peter reminds the church of his day that they, too, are, in a sense, foreigners: 1 Peter 2:11 Beloved, I beg you as foreigners and pilgrims, to abstain from fleshly lusts, which war against the soul; 12 having good behavior among the nations, so in that of which they speak against you as evildoers, they may by your good works, which they see, glorify God in the day of visitation.
Ezekiel 47:21 “So you shall divide this land to yourselves according to the tribes of Israel. 22 It will happen, that you shall divide it by lot for an inheritance to you and to the aliens who live among you, who will father children among you. Then they shall be to you as the native-born among the children of Israel. They shall have inheritance with you among the tribes of Israel. 23 It shall happen, that in whatever tribe the stranger lives, there you shall give him his inheritance,” says the Lord Yahweh.
Notes: 1) Refugees may become immigrants, but not all immigrants, legal or illegal, are refugees. The concept of border security probably was seldom considered in Bible times. In the verses above, “alien,” “foreigner,” and “stranger” seem to mean “non-Israelite.” Some of these would have been refugees.
2) Scripture quotations from the World English Bible, public domain. This post, on January 13, 2018, is a modified version of the original, which was posted July 27, 2017.
3) Lest there be any doubt, the United States is not equivalent to ancient Israel.
4) At least in Old Testament times, it seems that God would not have expected non-Israelites who came into the country for the purpose of subverting worship of Him, or to murder Israelites, to be treated as generously as the verses above indicate.