626. – Then when he says, by faith Rahab the harlot perished not with the unbelievers, he shows what was done by faith by one of the unbelievers, namely, by Rahab, as recorded in Joshua (chaps. 2 & 6). For when Joshua had sent spies to explore Jericho, they escaped with the aid of that woman who is called a harlot, i.e., an idolater. Or she was literally a harlot, with whom they stayed, not to sin but to hide. For the houses of such persons are visible especially at night. But they had come at night. Furthermore, her house was adjacent to the wall. But harlots take everyone without exception; ...therefore, it was easier for them to hide with her. Therefore, she was freed by faith, hence, he says, by faith Rahab the harlot did not perish with those who were disobedient [unbelievers], because she had given friendly welcome to the spies. She did not perish with the unbelievers, who perished corporally, because the spies had sworn to free her and everyone of her father's house; which they did. But why had they turned to her? Possibly because she would be less guilty, receiving all indiscriminately. Furthermore, it was not fitting that their safety be the occasion of death for the one harboring them. But by the fact that she was freed by receiving them is designated that those who receive the preachers of the gospel are delivered from eternal death: 'He that receives a prophet in the name of a prophet shall receive the reward of a prophet' (Mt. 10:11).
Source: Commentary on Hebrews