1 Chronicles 22:8-10 (KJV)
8 But the word of the Lord came to me, saying, Thou hast shed blood abundantly, and hast made great wars: thou shalt not build an house unto my name, because thou hast shed much blood upon the earth in my sight.
9 Behold, a son shall be born to thee, who shall be a man of rest; and I will give him rest from all his enemies round about: for his name shall be Solomon, and I will give peace and quietness unto Israel in his days.
10 He shall build an house for my name; and he shall be my son, and I will be his father; and I will establish the throne of his kingdom over Israel for ever.
1 Chronicles 22
God Gave Charge To Solomon To Build His Temple
It was God that told David that his son, Solomon, would be born for the purpose of building up the temple.