2 Samuel 7:27

For thou, O LORD of hosts, God of Israel, hast revealed to thy servant, saying, I will build thee an house: therefore hath thy servant found in his heart to pray this prayer unto thee.

David desired to make Jerusalem the religious center of the nation by erecting a magnificent temple for God, for he felt it was unfitting that the ark of God should rest in a tent while he himself dwelt in a palace. Through the prophet Nathan, God answered that David himself would not build a house for Him, but that the Lord would build a house for David. It was this promise of God to establish him that gave David heart to offer this prayer.

The cherished purpose to build was denied to David because he had shed blood abundantly and had made great wars. The work of building a house for God's name was instead entrusted to the seed who would come after him, his son Solomon, the peaceable man of rest to whom God would give rest and peace and quietness, and whose throne would be established forever. The house God promised to build for David meant lasting favor to him, to his posterity, and to the kingdom of Israel, with his house spoken of for a great while to come. Though denied his request, David received the message with gratitude and humility, marveling at his own unworthiness in view of how far God had brought him, and in that spirit he prayed and renewed his covenant with God.