David had emerged from an experience of chastening by the Lord for some sin he had committed and praised Him that His anger is temporary but His favor is permanent.
The title of this psalm is subject to two interpretations. It may mean that the psalmist composed it for the occasion of the dedication of the Lord's house. This would not be the dedication of Solomon's temple since David had already died when Solomon dedicated it. It could mean the tent that David erected in Jerusalem to house the ark of the covenant when he brought it into the city (2 Sam. 6:17). Perhaps this occasion was the dedication of the temple site (1 Chron. 21:26; 22:1). The Lord's chastening of the king preceded both of these events. The writer referred to this discipline in the psalm. Another possibility is that the title did not refer to the occasion of writing but to those occasions on which the Israelites were to use this psalm in national worship. This seems less likely to me in view of the references to chastening.