He did this because David had done what he approved and had not disregarded any of his commandments his entire lifetime, except for the incident involving Uriah the Hittite.
and the Lord will fulfill his promise to me, ‘If your descendants watch their step and live faithfully in my presence with all their heart and being, then,’ he promised, ‘you will not fail to have a successor on the throne of Israel.’
When they return to you with all their heart and being in the land where they are held prisoner, and direct their prayers to you toward the land you gave to their ancestors, your chosen city, and the temple I built for your honor,
The king stood by the pillar and renewed the covenant before the Lord, agreeing to follow the Lord and to obey his commandments, laws, and rules with all his heart and being, by carrying out the terms of this covenant recorded on this scroll. All the people agreed to keep the covenant.
hereby participate with their colleagues the town leaders and enter into a curse and an oath to adhere to the law of God which was given through Moses the servant of God, and to obey carefully all the commandments of the lord our Lord, along with his ordinances and his statutes.
Does it make you any more of a king that you outstrip everyone else in building with cedar? Just think about your father. He was content that he had food and drink. He did what was just and right. So things went well with him.