Thank you for the question on building the Temple, “Did God commanded Solomon to build a temple or was it only because David, his father, desired it?”
As one reads II Samuel 7, King David reflected that he lived in a palace while the Ark of the Covenant was in an open space being weather beaten day and night. He says this, “Here I am living in a palace of cedar, while the ark of God remains in a tent” (II Sam. 7:2). It was David’s desire to honor the LORD God by building a Temple that was worthy of God.
In verse 13–16, God reveals to David that he will NOT build the Temple of God, but one his descendant will build it. At this juncture, God does not reveal to David which of his children will build the Temple. It is assume that the one who ascends to the throne will be the one who builds the Temple.
As the sons of David rival for the throne, it is revealed that Solomon was to be king over Israel and with that came the charge by King David to build the Temple. David said this in I Kings 1, “The king then took an oath: “As surely as the LORD lives, who has delivered me out of every trouble, 30 I will surely carry out this very day what I swore to you by the LORD, the God of Israel: Solomon your son shall be king after me, and he will sit on my throne in my place” (A searchable online Bible in over 150 versions and 50 languages).
In the completion of the Temple, King David said this in I Chronicles 22, “Then he called for his son Solomon and charged him to build a house for the LORD, the God of Israel. 7 David said to Solomon: “My son, I had it in my heart to build a house for the Name of the LORD my God. 8 But this word of the Lord came to me: ‘You have shed much blood and have fought many wars. You are not to build a house for my Name, because you have shed much blood on the earth in my sight. 9 But you will have a son who will be a man of peace and rest, and I will give him rest from all his enemies on every side. His name will be Solomon, and I will grant Israel peace and quiet during his reign. 10 He is the one who will build a house for my Name. He will be my son, and I will be his father. And I will establish the throne of his kingdom over Israel forever.’
11 “Now, my son, the LORD be with you, and may you have success and build the house of the LORD your God, as he said you would. 12 May the Lord give you discretion and understanding when he puts you in command over Israel, so that you may keep the law of the LORD your God. 13 Then you will have success if you are careful to observe the decrees and laws that the LORD gave Moses for Israel. Be strong and courageous. Do not be afraid or discouraged” (NIV).
God foretold David that one of his sons would build the Temple that he wanted to build for God. The son that ascended the throne was Solomon. Thus David charged him to fulfill his desire to build that Temple that God had revealed to him.
SUMMARY: God revealed to David that the son who ascended his throne will be the one who builds the Temple. That son was Solomon and David gave him that charge to fulfill it.
For more perspectives: