I have never noticed this before, but the genealogy in Matthew has a few oddities.
and Judah the father of Perez and Zerah by Tamar, and Perez the father of Hezron, and Hezron the father of Ram, (Mat 1:3)
The story of Judah and Tamar is a good one. Judah disgraced Tamar by not providing her his youngest son to be her husband in order to provide an heir for his eldest son who had died. Now Judah lost his first two sons after they married Tamar, but both were evil. Some teachings say they died due in part to the wicked acts that Judah committed by selling Joseph into slavery. So Judah thought Tamar was a temple prostitute and had sex with her and she conceived twins. During delivery, Zerah stuck his hand out of the womb first and then withdrew it, but not before the midwife tied a scarlet thread around it. Perez was actually the first to be born and then Zerah followed.
and Salmon the father of Boaz by Rahab, and Boaz the father of Obed by Ruth, and Obed the father of Jesse, (Mat 1:5)
The story of Ruth and Naomi. Ruth was the daughter in-law to Naomi, but her husband died. In fact, both of Naomi’s sons died. Ruth, who was a Moabite, refused to leave Naomi and they travelled back to Israel. Ruth scavenged food, but eventually wed Boaz. Ruth had a child, Obed, but that child was given to Naomi to raise as it would carry on the legacy of her son who died. Boaz redeemed Naomi and cursed himself by marrying a Moabite.
and Jesse the father of David the king. And David was the father of Solomon by the wife of Uriah, (Mat 1:6)
The mother of Solomon was Bathsheba, but she was not listed by name but rather by her relationship as she was an adulteress. Now her first child that she conceived with David died once born as punishment for their sins. She was known as the wife of Uriah, who David had killed to try and cover up his shame. After being confronted by the prophet Nathan, David wrote Psalm 51.
and Jacob the father of Joseph the husband of Mary, of whom Jesus was born, who is called Christ. (Mat 1:16)
Mary was with child when she married Joseph. Both are from the line of David, but only Joseph claimed lineage from Solomon. That was required to even be considered the Messiah. Matthew never claims that Joseph is the father, but implies he can claim the lineage as being so.
Obed still shows the lineage as coming from Boaz even though he was there to redeem the property and family name of Elimelech, the husband of Naomi. Boaz’s children would have been cut off from the his people since he married Ruth, the Moabite. That is why the other in that family, who was a closer redeemer than Boaz denied his right. He would have lost everything. Solomon was the son of an adulteress and the kingship should not have passed to him except David changed the right of birth order.