In the Book of Joshua (ch. 6) we find that when the Israelites entered Jericho, they destroyed and plundered the city. Yet: “Ve’et rachav hazona ve’et beit aviha ve’et kol asher lah hecheya yehoshua, vateshev bekerev yisrael ad hayom hazeh ki hechbia et hamal’achim asher shalach yehoshua leraggel et yericho – Yehoshua kept alive Rahab the harlot and her father’s house and all that belonged to her and she [and her family] dwelled in the midst of Israel until this very day, because she hid the messengers that Joshua sent to spy out Jericho” (Joshua 6:25).
The Radak (ad loc.) explains that the words “kept alive” mean that Joshua issued a command to keep the oath the messengers (Caleb and Phineas) made to Rahab to keep her and her family alive (Joshua 2:14). He also notes that others explain the term “kept alive” to mean that Joshua arranged for them food, money, and inheritance (land) in order that they would live, as evidenced by the verse’s continuation, “[A]nd she dwelled in the midst of Israel until this very day.”
The words “kept alive” are also explained to refer to Joshua marrying Rahab, for when Bnei Yisrael saw that Joshua took Rahab for a wife, they all cleaved to her father’s house. To answer the obvious difficulty with a Jew marrying a woman from the seven nations, it is explained that Rahab and her father’s house were not indigenous to Canaan but had recently come there, and therefore were not considered part of the seven nations (see Tosafot, Megillah 14b s.v. “de’igga’yera” and Tosafot Sotah 35b s.v. “l’rabot”).
The Radak then offers an alternate explanation postulating that Rahab and her family were indeed of the seven nations, but when Joshua’s messengers arrived in Jericho, she (and presumably her family, as well) converted. As the Children of Israel had not yet entered the land, the instructions against leaving any of the inhabitants alive and marrying them were not yet applicable. This interpretation follows the opinion that the seven nations are only forbidden in marriage if they don’t convert.