Deuteronomy 7:1–6 forbade Israelites from intermarrying with the nations that occupied the land of Israel at that time in order to prevent the Israelites from serving other gods. Deuteronomy 23:3 also forbids the immediate descendants of Ammon and Moab from joining the covenant community and the Egyptians are likewise prohibited in Deuteronomy 23:7–8.1
The Bible does not prohibit marriage of foreign women (e.g., Genesis 16:3; Genesis 41:45; Exodus 2:21; Numbers 12:1; 2 Samuel 3:3) where such a marriage does not involve a compromise of faith or practice.2 The key idea behind the prohibition is not ethnicity but religion.3 For example, where a Moabite such as Ruth was willing to turn her back on her gods and put her faith in the Lord, she was allowed to marry Boaz without such a marriage being deemed sinful.
2 For they have taken some of their daughters to be wives for themselves and for their sons, so that the holy race has mixed itself with the peoples of the lands. And in this faithlessness the hand of the officials and chief men has been foremost.”