This is a good question and I can see your point. The name/word “Rahab”is mentioned in two settings. Other than referenced as a person in Matthew’s genealogy of Jesus (David‘s great-grandmother), the other references to “Rahab” where symbolic.
“Rahab“, a “sea monster,” came to symbolize Egypt and her Pharaoh who opposed Moses and Israel. Isaiah 51:9, 10 alludes to Jehovah’s delivering Israel from Egypt: “Are you not the one that dried up the sea, the waters of the vast deep? The one that made the depths of the sea a way for the repurchased ones to go across?” At Isaiah 30:7 “Rahab” is again connected with Egypt. Psalm 87:4 mentions “Rahab” where Egypt appropriately fits, as the first in a list of Israel’s enemies, along with Babylon, Philistia, Tyre, and Cush. The Targums use “the Egyptians” in this verse, and at Psalm 89:10 they paraphrase “Rahab” in such a way as to link the term with Egypt’s arrogant Pharaoh whom Jehovah humiliated.
Considering what Paul tells us at Hebrews 11:30, 31 and what James says at 2:24, 25, I am confidant that they are referring to the same “Rahab” mentioned in Joshua and Matthew as a person and one in the same.