It seems to me that there is a fairly big contradiction in whether or not God allowed the Israelites to intermarry. How does one explain this? "Now kill all the boys. And kill every woman who has slept with a man, but save for yourselves every girl who has never slept with a man" (Numbers 31:17-18)
"If you notice among the captives a beautiful woman and are attracted to her, you may take her as your wife" (Deuteronomy 21:11)
"Do not intermarry with them. Do not give your daughters to their sons or take their daughters for your sons, for they will turn your sons away from following me to serve other gods, and the Lord’s anger will burn against you and will quickly destroy you" (Deuteronomy 7:3-4)
I can certainly see why you find there to be a contradiction here. Yet, I believe that there is not a contradiction, and please allow me to explain. God was very concerned with his people remaining Israelites and being part of Israel. You may find it surprising, but the fact is that God did not refuse to let those who were not born Israelites to become part of Israel. Abraham’s slaves and servants were part of the people who eventually became "Israel." God made provision for people to come under the covenant of Moses. It is true that the Jews were not particularly evangelistic, yet we know both from biblical and from extra-biblical sources that many people in the Roman world and even earlier were attracted to Judaism and were eventually, after a lengthy process, admitted to being a Jew. These believers were known as proselytes. They were required to undergo a baptism/cleansing and they were only accepted provisionally, but eventually their children were accepted as true Jews. This can help to explain the fact that Jews in different parts of the world have physical traits which are a compromise between the local people that those of semitic peoples. The Jews have always taken in non-Jews.
This brings me back to your question. It is true that when the Jews conquered people they were allowed by God to incorporate some of those conquered into their families. The girls who were taken into the Jewish families as described in Numbers 31:17-18 represented little if any threat to the Jews losing their Jewishness. For a Jewish man to marry a woman who was still a part of a gentile nation, like Samson did, was both a violation of God’s commandments and a clear danger for these men to become non-Jewish. For the Jews to take in an adult woman who was a non-Jew and whose family remained non-Jews also represented a risk to the Jewishness of the Jews. This prohibition against mixed marriages which were a clear threat to Israel’s uniqueness is found in Deuteronomy 7:3-4 as you mentioned. However, for the Jews to marry a captive woman who was permanently fully cut off from her people represented sufficiently small threat to the Jews remaining faithful to the covenant of Moses that God allowed for this. For a Jew to take for a wife a Canaananite woman who was still an active and practicing worshipper of Baal was one thing, but to marry a captive who had no or virtually no ties to her pagan roots was another.