Perhaps a better question would be, "Why was Rahab included in Matthew's genealogy of Jesus Christ (in Matthew 1)":
This is the genealogy of Jesus the Messiah the son of David, the son of Abraham: Abraham was the father of Isaac,Isaac the father of Jacob, Jacob the father of Judah and his brothers, Judah the father of Perez and Zerah, whose mother was Tamar, Perez the father of Hezron, Hezron the father of Ram,
Ram the father of Amminadab, Amminadab the father of Nahshon, Nahshon the father of Salmon, Salmon the father of Boaz, whose mother was Rahab, Boaz the father of Obed, whose mother was Ruth, Obed the father of Jesse, and Jesse the father of King David.
In addition to all the reasons given by providers of the above answers, I suggest that Rahab's mention is Hebrews may be because she figured to prominently in the genealogy of the Messiah, Jesus of Nazareth.
If I were Matthew, and I also happened to be the author of Hebrews, I guess I'd have included Rahab in my Hall of Faith instead of the spies, as full of faith as they likely were. Moreover, given a limited amount of space, the author of Hebrews by selecting a limited few stalwarts of faith was at the same time deflecting the names of other stalwarts. He included them, to be sure, but collectively, not individually, as in the following verses:
Women received back their dead, raised to life again. There were others who were tortured, refusing to be released so that they might gain an even better resurrection. Some faced jeers and flogging, and even chains and imprisonment. They were put to death by stoning; they were sawed in two; they were killed by the sword. They went about in sheepskins and goatskins, destitute, persecuted and mistreated—-the world was not worthy of them. They wandered in deserts and mountains, living in caves and in holes in the ground.
These were all commended for their faith, yet none of them received what had been promised, since God had planned something better for us so that only together with us would they be made perfect (Hebrews 11:35-40 NIV, my italics).