David wishes to build a temple, because he was arguing that he should not be living in a palace while God lives in a tent. Nathan, a prophet, agrees. However, that night Nathan has a dream in which God informs him that David should not build him a temple for three reasons.
Firstly, God has not commanded it, and has never complained about living in a tent before. Secondly, God is still working to build David and his house up and establish the Israelites in the Promised Land. Thirdly, God will establish one of David’s sons as king; he will build the temple, and his house will never be out of power.
When Nathan reports this to David, David prays to God, thanking him for these revelations. David defeats the enemies of Israel, slaughtering Philistines, Moabites, Edomites, Syrians, and Arameans. He then appoints a cabinet.