Then he called for Solomon his son, and charged him to build a house for Yahweh, the God of Israel.
In this light, we must discern David's mistaken interpretation of God's prophecy through Nathan.  Those magnificent messianic passages of the Psalms, written by David under the inspiration of the Holy Spirit, may not have been fully understood, even by David himself, as an apostle stated  (1 Peter 1:10-12).