What is the meaning of Matthew 1:5-17?

5 And Salmon begat Booz of Rachab; and Booz begat Obed of Ruth; and Obed begat Jesse;  6 And Jesse begat David the king; and David the king begat Solomon of her that had been the wife of Urias;  7 And Solomon begat Roboam; and Roboam begat Abia; and Abia begat Asa;

8 And Asa begat Josaphat; and Josaphat begat Joram; and Joram begat Ozias; 9 And Ozias begat Joatham; and Joatham begat Achaz; and Achaz begat Ezekias; 10 And Ezekias begat Manasses; and Manasses begat Amon; and Amon begat Josias;  11 And Josias begat Jechonias and his brethren, about the time they were carried away to Babylon:

12 And after they were brought to Babylon, Jechonias begat Salathiel; and Salathiel begat Zorobabel; 13 And Zorobabel begat Abiud; and Abiud begat Eliakim; and Eliakim begat Azor; 14 And Azor begat Sadoc; and Sadoc begat Achim; and Achim begat Eliud;  15 And Eliud begat Eleazar; and Eleazar begat Matthan; and Matthan begat Jacob;

16 And Jacob begat Joseph the husband of Mary, of whom was born Jesus, who is called Christ. 17 So all the generations from Abraham to David are fourteen generations; and from David until the carrying away into Babylon are fourteen generations; and from the carrying away into Babylon unto Christ are fourteen generations. (Matthew 1:5-17 KJV)

William Burkitt’s New Testament Commentary

Observe, Here are several women mentioned in our Savior’s genealogy, and all, or most of them, have a brand of infamy upon them. Thamar was one, with whom her father-in-law, Judah, committed incest; Rahab is called an harlot; Ruth came of Moab, whom Lot begat of his own daughter; and Bathsheba, the wife of Uriah, was one with whom David had committed adultery.

Now the wisdom of God has thought fit to leave all this upon record for several ends and purposes.

1. To denote the freeness of God’s grace, which extends itself in the saving effects and benefits of it to them that are most unworthy and ill-derserving.

2. To encourage the greatest sinners to unto Christ by faith, and seek to be ingrafted into him: for as Christ, by the power of his godhead, did purify our nature from all the pollution of our ancestors, so he can, by the power of his grace and spirit, sanctify our persons and natures, how foul and impure soever they either are or have been.

3. Hereby our Lord gives us to understand, That he came to save the most notorious sinners, as well as those lives have been less scandalous.

4. This is recorded for the support of such as are illegitimate and base-born, how vile soever their parents’ sin has rendered them in the eyes of men, it is their own sin only which exposes them to contempt in the sight of God. It is not illegitimacy, but unregeneracy, that makes us objects of God’s wrath.