When David provoked the anger of God by counting the fighting men in Israel, the punishment was so severe. Then God commanded David to build an altar on the threshing floor of Araunah the Jebusite (1 Chronicles 21) to pray to the LORD to have mercy on Israel. David called on the Lord, and the Lord answered him with fire from heaven on the altar of burnt offering.
David then decided to build the Temple there at the threshing floor of Araunah the Jebusite. David then commenced the building of the Temple of God immediately. But God already forbade David from building the Temple as David had shed much blood.
1 Chronicles 22:1-10 (NIV)
Then David said, “The house of the Lord God is to be here, and also
the altar of burnt offering for Israel.”
So David gave orders to assemble the foreigners residing in Israel,
and from among them he appointed stonecutters to prepare dressed stone
for building the house of God. He provided a large amount of iron to
make nails for the doors of the gateways and for the fittings, and
more bronze than could be weighed. He also provided more cedar logs
than could be counted, for the Sidonians and Tyrians had brought large
numbers of them to David.
David said, “My son Solomon is young and inexperienced, and the house
to be built for the Lord should be of great magnificence and fame and
splendor in the sight of all the nations. Therefore I will make
preparations for it.” So David made extensive preparations before his
death.
Then he called for his son Solomon and charged him to build a house
for the Lord, the God of Israel. David said to Solomon: “My son, I had
it in my heart to build a house for the Name of the Lord my God. But
this word of the Lord came to me: ‘You have shed much blood and have
fought many wars. You are not to build a house for my Name, because
you have shed much blood on the earth in my sight. But you will have a
son who will be a man of peace and rest, and I will give him rest from
all his enemies on every side. His name will be Solomon, and I will
grant Israel peace and quiet during his reign. He is the one who will
build a house for my Name. He will be my son, and I will be his
father. And I will establish the throne of his kingdom over Israel
forever.’
Prophet Nathan also prophesied long before David married Bathsheba, the mother of Solomon, that David was not the one to build the Temple.
He is the one who will build a house for my Name, and I will establish
the throne of his kingdom forever. I will be his father, and he will
be my son. When he does wrong, I will punish him with a rod wielded by
men, with floggings inflicted by human hands. (2 Samuel 7:13-14, NIV)
Before Solomon was born, God already decided that Solomon should build the house of the Lord. David was not qualified because his hands were stained with blood. Moreover, David's purpose was to establish the kingdom of Israel. After 300 years of war with the inhabitants of Canaan, it was time to make an end to turmoil. David had the responsibility to build a powerful nation for Israel, the people of God. The reign of Solomon was the right time to build the Temple. God wanted to build His house in a peaceful environment, without shedding of blood in the country. After David defeated all enemies of Israel, the nation was in peace and his son Solomon received the honor of building the Temple of the LORD.