Matthew 1:1-17
The book of Matthew opens with a stylized genealogy of Jesus of Nazareth (Matthew 1:1-17). Matthew presents the list in three parts—from Abraham to David, from David to the captivity in Babylon, and from the captivity to Christ—each with fourteen generations. The genealogy is perfectly correct in every way.
Except one.
What Matthew records is not Christ's biological ancestry but His legal one. Verse 16 gives the proof: "And Jacob begot Joseph the husband of Mary, of whom was born Jesus who is called Christ." It is Joseph's family tree! Remember, Christ was not begotten of Joseph but of the Holy Spirit. Legally, Christ could trace his ancestry back to David through his "father" Joseph, though He had not one drop of Joseph's—or Jehoiachin's—blood!
We must remember a major purpose of Matthew's gospel: to present Jesus of Nazareth as the Messiah to the Jews. The Jews were, and still are, very particular about genealogies. Anyone claiming to be the Messiah would have to present a bona fide, airtight ancestry back to David if he were to be taken seriously (see Psalm 110:1; Isaiah 9:6-7; Jeremiah 23:5-6; etc.). Matthew does just that in introducing Jesus in the first verses of his book.
Thus, Jesus, untainted by Jehoiachin's curse (Jeremiah 22:30), has a legal claim to the throne of David through His stepfather, Joseph. Such a thing was legally acceptable under Jewish law.

This opening verse establishes Jesus as of a kingly line and heir to David's throne, the chosen Seed to whom the promises made to Abraham were confirmed. Matthew's genealogy, arranged in three groups of fourteen from Abraham to David, David to the Babylonian captivity, and captivity to Christ, records His legal rather than biological ancestry. Since Christ was begotten of the Holy Spirit, not Joseph, He traces His claim to David's throne through His stepfather, untainted by Jehoiachin's curse yet legally acceptable under Jewish law. This satisfied the Jews' strict demand for verifiable Davidic descent in the Messiah. The line includes four women, Tamar, Rahab, Ruth, and Bathsheba, and varied characters, showing God works through anybody He desires, unlimited by human imperfections.