No one knows for sure why James moves to Rahab as his second example, though some suggestions are clever. Hospitality seems the best explanation: the messanists for not showing it to the poor, Abraham for entertaining strangers, and Rahab for welcoming Israel’s spies.
The Canaanite prostitute Rahab, whose story of hospitality is told in Joshua 2 and whose reward is found in 6:16-25, creates problems for modern interpreters and historians while she resolves a faith-works relationship for James. The writer of Hebrews also saw Rahab as an example of faith and hospitality (11:31), while Matthew seems to depict her as a sinful Gentile woman who played a role in the Messiah’s geneaology (1:5). Josephus makes her an inn-keeper instead of a prostitute and therefore the spies are only there for dinner (Ant 5.7-15). In 1 Clement 12 we discover a prophetic type of atonement in the red cord and in later Judaism Rahab was classified as a proselyte but this isn’t James’ point. For James, Rahab was (1) a prostitute, (2) justified by works, and (3) one who welcomed the spies and sent them off surreptitiously.
For James, she illustrates that faith accompanied by deeds of mercy (works) is the kind of faith that works/saves.
James closes the sub-text (2:24-26), the unit (2:20-26), and the entire chp with this conclusion: “As the body without the spirit is dead, so faith without deeds is dead.” That’s been his point all along and it’s his intent. If read within that point and with that intent, James should make sense for Protestants.
Faith and works are inseparable for James.