This account is one of the miracles of God found in the Bible. Because of the promise to King David the line through Solomon had to bring the Messiah. But when God declared the Jeconiah (or Coniah) curse, the Messiah could not come through Solomon. Thus Nathan, another son of David, brought about the promised One.
The prophecies of the OT were fulfilled with Mary’s line from Nathan bringing the Messiah. But with Joseph’s line, given in Matthew, the Annointed One came through adoption and Solomon’s line.
He is the rightful King through Joseph, and the rightful Priest through Mary, and it just so happens there were 14 generations from Abraham to David, 14 generations from David to the deportation to Babylon, and 14 generations from the deportation to Babylon to the Christ.
I’m sure it was all just coincidence!