Matthew mentions a handful of women in his genealogy of Christ. This is odd. If he was following the convention of the time, which held that descent, inheritance, and “Jewishness” were passed down the male line, he wouldn’t have needed to include any women. But if he was attempting to give a holistic family tree, the few women he does mention are wildly insufficient. So what’s he doing?
I think each time he does this, it’s to point out something surprising about the relationship in question. Tamar is the first mentioned; she, having survived two husbands who God struck down for their sins, was regarded as cursed, and was ostracized from her family; through cunning deceit, including deliberately getting her father-in-law to impregnate her under the guise of being a prostitute, she proved that she was being mistreated, and so acquired for herself the security and status of marriage, bearing sons to a husband who was not struck down for his sins. Rahab is mentioned after her; she was a Canaanite, and quite possibly a prostitute or the owner of a brothel. Yet, she was also regarded as a holy and righteous woman, without whom the Israelites could not have conquered Jericho. Ruth is next; she was a Moabite, a member of a nation normally in conflict with the Israelites, but she demonstrated her faithfulness to God so strongly that an entire book of the Old Testament is named for her. And then there is Bathsheba, the wife of Uriah; King David committed adultery with her, and then had Uriah murdered to cover up the subsequent pregnancy.