Then he called for Solomon his son, and charged him to build a house for Yahweh, the God of Israel.
Of course, God forgave David for this misunderstanding and mistake.  As a forerunner and type of Messiah himself, David's temple was overruled and utilized by the Lord in the ultimate achievement of the divine purpose of providing salvation to be made available for all men.  God allowed it to stand under the old covenant as a type of the true temple of God, namely, the Holy Church of Jesus Christ.  Such a thing was possible only because the temple incorporated so many features of the tabernacle which it replaced (As conclusively indicated in the Book of Hebrews).