But the word of the LORD came to me, saying, ‘You have shed much blood and have waged great wars. You shall not build a house to my name, because you have shed so much blood before me on the earth.
Though Solomon was young and tender, he was capable of receiving instructions, which his father accordingly gave him, concerning the work for which he was designed. When David came to the throne he had many things to do, for the foundations were all out of course; but Solomon had only one thing in charge, and that was to build a house for the Lord God of Israel, Ch1 22:6.
Commenting on 1 Chronicles 22:6-16
But the word of the Lord came to me,.... The word of prophecy, as the Targum, by the mouth of Nathan the prophet: saying; as follows, which though not expressed in the book of Samuel before referred to, is here recorded by divine inspiration: thou hast shed blood abundantly; Kimchi thinks this refers to the blood of Uriah, and those gallant men that were slain...
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.