Matthew opens his account of the Gospel of Jesus Christ with the most boring part of the Bible. The family tree of Jesus. To a person who has never read the Bible, the begats are the point at which that person, especially a young person, begins to wonder just how long it is going to take to get to the exciting part. The first family line is in Genesis. So right away, we run into a long list hard-to-pronounce names. There is a point, however to the family lines in the Bible. One of Matthew's main purposes is to present Jesus Christ as The King. From beginning (the lineage) to end (Matt 25), Christ is portrayed as the expected King. Jesus is not merely the King because he is God. He is the earthly king of the Jews as well.
While it is true that the Jewish leaders rejected Jesus as king (John 19) It is also true that Jesus family tree shows his royal pedigree. The King had to come from the line of King David. Look at the list in Matthew's Gospel and you will see that his line runs from Abraham through David through his adopted father Joseph. Notice verse 16 says "16Jacob was the father of Joseph the husband of Mary, by whom Jesus was born, who is called the Messiah." The verse does not say Joseph was the father of Jesus. We know Mary was a virgin.
You might ask how Jesus is qualified to be king if Joseph is not his biological father. It is true that adopted children in Jewish society had all the rights of biological children. And later in his life Jesus was referred to as the son of Joseph so he was recognized that way. But there is even a better answer.
Mary was in the royal line as well. There is a fork in the road at David. Joseph's line came through Solomon. Mary's came through David's other son Nathan. So Jesus is doubly qualified. This is also important because in Joseph's line there is a man named Jeconiah. Jeconiah was put under a curse by God (Jeremiah 22:30). His ancestors were forbidden from taking the throne. So if Jesus were only in line through Joseph, that would have actually disqualified Jesus from being king. Another interesting thing about Jesus family tee is who is included in it. There are gentiles, women (even a harlot) and some rather unsavory people.
The point of this is that God uses whom he chooses. No one is chosen by God because of any special righteousness or qualificatiosns. In fact, the people God chose for His puproses were sinners. Just like us.