We now skip a few hundred years ahead, all the way to the capture of Jerusalem. After David brought the Ark of Covenant to Jerusalem, David asked God whether he could build the Temple for him. God replied,
(2Sa 7:10-11 ESV) 10 And I will appoint a place for my people Israel and will plant them, so that they may dwell in their own place and be disturbed no more. And violent men shall afflict them no more, as formerly, 11 from the time that I appointed judges over my people Israel. And I will give you rest from all your enemies. Moreover, the LORD declares to you that the LORD will make you a house.
God promised to give Israel a time of peace, after centuries of warfare spent in conquering the Promised Land. And God promises to “make you a house,” meaning, most likely, a dynasty. In the language of the day, it was likely he was speaking of “the house of David,” meaning his dynasty or line of descendants.
(2Sa 7:12-13 ESV) 12 When your days are fulfilled and you lie down with your fathers, I will raise up your offspring after you, who shall come from your body, and I will establish his kingdom. 13 He shall build a house for my name, and I will establish the throne of his kingdom forever.
Here God speaks of Solomon, and God’s promise is that Solomon’s throne (which is David’s throne, as well) forever.
(2Sa 7:14-16 ESV) 14 I will be to him a father, and he shall be to me a son. When he commits iniquity, I will discipline him with the rod of men, with the stripes of the sons of men, 15 but my steadfast love will not depart from him, as I took it from Saul, whom I put away from before you. 16 And your house and your kingdom shall be made sure forever before me. Your throne shall be established forever.'”
In Deuteronomy, God had declared all Israel “sons of … God.” But here God creates a special, personal relationship with Solomon — a better, closer kind of sonship — a love like that of a father, so that sin will result in discipline but not an end to God’s love. Therefore, David’s dynasty will never end, even though not all his descendants will be holy men.
Now, it was hardly obvious at this point in history, but we now know that this covenant resulted in the Messiah coming from David’s descendants and claiming David’s throne. Indeed, some of the earliest Messianic prophecies are found in David’s Psalms, possibly written in response to these very promises.
Now, why did God choose David? Well, why did he choose Abraham? David was a great warrior and good king — for a while. But in the next several chapters, we soon see that he had feet of clay, and he hardly set the perfect example of a good king. David was a sinful man — but he was humble before God and quick to repent.
David, like all Christians, was elected by God because of his faith and heart, not the excellence of his obedience and understanding. David made mistakes — huge mistakes — but his heart remained soft in God’s hands. God disciplined him severely at times, and David remained a man of God to the end.