Saint Thomas Aquinas
Man’s relations with foreigners are twofold: peaceful, and hostile: and in directing both kinds of relation the Law contained suitable precepts. For the Jews were offered three opportunities of peaceful relations with foreigners.
First, when foreigners passed through their land as travelers.
Secondly, when they came to dwell in their land as newcomers. And in both these respects the Law made kind provision in its precepts: for it is written (Exodus 22:21): “Thou shalt not molest a stranger [advenam]”; and again (Exodus 22:9): “Thou shalt not molest a stranger [peregrino].”
Thirdly, when any foreigners wished to be admitted entirely to their fellowship and mode of worship. With regard to these a certain order was observed. For they were not at once admitted to citizenship: just as it was law with some nations that no one was deemed a citizen except after two or three generations, as the Philosopher says (Polit. iii, 1). The reason for this was that if foreigners were allowed to meddle with the affairs of a nation as soon as they settled down in its midst, many dangers might occur, since the foreigners not yet having the common good firmly at heart might attempt something hurtful to the people. Hence it was that the Law prescribed in respect of certain nations that had close relations with the Jews (viz., the Egyptians among whom they were born and educated, and the Idumeans, the children of Esau, Jacob’s brother), that they should be admitted to the fellowship of the people after the third generation; whereas others (with whom their relations had been hostile, such as the Ammonites and Moabites) were never to be admitted to citizenship; while the Amalekites, who were yet more hostile to them, and had no fellowship of kindred with them, were to be held as foes in perpetuity: for it is written (Exodus 17:16): “The war of the Lord shall be against Amalec from generation to generation.“
Saint Thomas Aquinas: Summa Theologica, the second part of the first part, question 105, article 3 (I-II, Q. 105, Art. 3).