In Sefer Shemuel, Hashem does not explain why David was not allowed to build the Beit HaMikdash leading commentators to look elsewhere for the reason. Rashi and others find it in Devarim, which sets peace as a precondition for the building of the Mikdash. Since David had not yet achieved security, the Mikdash had to wait until Shelomo reigned. David had done nothing wrong; the time was simply not ripe.
Radak, in contrast, turns to verses in Melakhim and Divrei HaYamim which suggest that Hashem refused to allow David to build the Mikdash due to faults in his character. David's spilling of innocent blood disqualified him from meriting to build such a holy site.
Finally, Ralbag finds the explanation for David's rejection in Sefer Shemuel itself. Like Rashi, he finds no fault in David. To the contrary, he suggests that since David had already merited so much (becoming king and vanquishing his enemies) Hashem thought it only proper that he share the glory and give someone else the privilege of building Hashem's House.
Lack of Stability and Peace
A prerequisite for building the Beit HaMikdash was that the nation be settled in the land and at peace from its enemies. This was not yet accomplished during the reign of David and so the building was postponed until Shelomo took the throne.
Necessary conditions for Mikdash – According to Devarim 12, the Beit HaMikdash is supposed to be built only after the people have achieved peace and security in Israel (הֵנִיחַ לָכֶם מִכׇּל אֹיְבֵיכֶם מִסָּבִיב וִישַׁבְתֶּם בֶּטַח). Malbim explains that to meet these conditions it was necessary not only to have lasting rest from enemies, but also a continuous monarchy. Though David is given the title "king", it is only with the reign of Shelomo that his rule became dynastic,1 and thus the Mikdash was first built in Shelomo's era.
"וַי"י הֵנִיחַ לוֹ מִסָּבִיב מִכׇּל אֹיְבָיו" – The opening of the story would seem to suggest that the requirement for peace was indeed met before David asked to build the Mikdash.2 Malbim explains that though there was a temporary respite from war (which is what spurred David to make the request), Hashem knew that many more wars were to be fought3 and that the short lull was no different than the many periods of quiet during the era of the Shofetim.4
Hashem's reply to David's request – Malbim explains that even though Hashem does not appear to explain why He is rejecting David's request, His reply does in fact address the concerns discussed above (the need for both stable government and security from enemies). Hashem points out that when He chose David, he was a simple shepherd rather than a son of a king, and thus had no stability in his rule. He then emphasizes how He has helped David conquer his enemies, highlighting that peace has not yet been achieved.
Hashem's promises – Hashem ends his speech to David with a twofold promise, that He will root Israel in security (verse 10) and give David a dynasty (verse 12). In so doing, Hashem ensures that when David's son reigns, all the conditions for building the Mikdash will be in place.
Man of war – This position's reasoning for the rejection of David's request fits the explanation that Shelomo gives to Chiram in Melakhim I 5: "כִּי לֹא יָכֹל לִבְנוֹת בַּיִת לְשֵׁם י"י אֱלֹהָיו מִפְּנֵי הַמִּלְחָמָה אֲשֶׁר סְבָבֻהוּ". It is also the simple understanding of David's own words to Shelomo, that Hashem prohibited the building because: "וּמִלְחָמוֹת גְּדֹלוֹת עָשִׂיתָ/ כִּי אִישׁ מִלְחָמוֹת אַתָּה".
"דָּם לָרֹב שָׁפַכְתָּ" – Ibn Kaspi explains that these words should be understood in light of those that follow, "וּמִלְחָמוֹת גְּדֹלוֹת עָשִׂיתָ". Hashem is not saying that David's spilling of blood was problematic or undesirable,5 only that it betrayed how the nation had not yet achieved security.
Choice of Shelomo – When David explains why Shelomo will build the Mikdash instead of him, he emphasizes how Hashem promised that in his era there will finally be peace: "וַהֲנִיחוֹתִי לוֹ מִכׇּל אוֹיְבָיו מִסָּבִיב כִּי שְׁלֹמֹה יִהְיֶה שְׁמוֹ וְשָׁלוֹם וָשֶׁקֶט אֶתֵּן עַל יִשְׂרָאֵל בְּיָמָיו".
Shelomo's name – Shelomo's very name highlights how his character and reign stood for peace.
Purpose of the Beit HaMikdash
Malbim points out that, in contrast to the portable Mishkan, the Beit HaMikdash was meant to be a permanent structure reflecting the stability of Israel as whole, and as such, a stable dynasty was a prerequisite for its construction. In addition, as a house of peace, it needed to built in an era of peace, by a man of peace.
One might add that if the Mikdash is meant to be an international house of prayer which will serve to sanctify Hashem throughout the world,6 this is only possible when all countries recognize Israel.
Defect in David
David was prohibited from building the Beit HaMikdash due to flaws in his character, specifically his having spilled much blood.
"דָּם לָרֹב שָׁפַכְתָּ" – These sources7 point to this verse as evidence that David could not build the Beit HaMikdash due to his spilling of blood. They differ regarding which blood is being spoken about and why it was problematic:
Death of the deserving – Rambam claims that even though David was merciful to his fellow Israelites and only spilled the blood of non Jews and heretics, this nonetheless betrays a certain "cruelty" in his character.8
Spilling of innocent blood – Radak, in contrast, blames David for the killing of innocents,9 suggesting that David was being held accountable either for the death of Uriah (Shemuel II 11),10 the death of the priests in Nov (Shemuel I 22),11 or the deaths of righteous non-Jews whom he killed in battle.12 Prof. Y. KiI13 adds that it might also refer to the many deaths that occurred during the civil war between David and Ishboshet.
Blood of Israelite soldiers – Hoil Moshe points to David's general desire to embark on wars of conquest.14 David's willingness to endanger lives when not necessary for purposes of defense was problematic.15
Shelomo to Chiram: "מִפְּנֵי הַמִּלְחָמָה" – Radak suggests that when Shelomo tells Chiram that his father could not build the Temple due to the many wars which surrounded him, implying that his father simply had no opportunity to do so, he was not telling the full truth. Shelomo had made up a plausible excuse since it would not be respectful to say that Hashem had prohibited David from building or that his father "had blood on his hands".
"וּמִלְחָמוֹת גְּדֹלוֹת עָשִׂיתָ/ כִּי אִישׁ מִלְחָמוֹת אַתָּה" – David himself also speaks of war as one of the reasons given by Hashem to explain his inability to build the Mikdash. These sources might explain that the phrases "אִישׁ מִלְחָמוֹת" and "וּמִלְחָמוֹת גְּדֹלוֹת עָשִׂיתָ" should be understood in light of the accompanying "דָּמִים רַבִּים שָׁפַכְתָּ". They are not neutral statements describing external factors that made the building difficult, but derogatory assessments of David's character and priorities.
Era of peace? Radak agrees that the commandment to build the Beit HaMikdash only applies in an era of peace, but suggests that the opening verse of our chapter (וַי"י הֵנִיחַ לוֹ מִסָּבִיב מִכׇּל אֹיְבָיו) proves that this condition had been met. At this point in his reign, David had already been victorious over all attacking enemies. The wars described in later chapters refer not to wars of defense, but to wars of conquest that David fought voluntarily. Thus, this was not the reason for the disqualification of David.
Why doesn't Natan give a reason?
Radak suggests that despite the text's silence in Shemuel II, the prophet really had told David why he was not allowed to build Hashem's house, as implied by David's words in Divrei HaYamim.16
Alternatively, if Radak is correct in relating the rejection to David's killing of Uriah, Natan is silent because he could not speak of crimes that David had not yet committed.
Hashem's promises to David – Hashem's reply to David is somewhat difficult for this approach. If David was prohibited from building the Mikdash due to faults in his character, one would expect the tone of Hashem's refusal to be negative, when it is, in fact, the opposite. If Hashem is in effect punishing David through the refusal, why reward him with an everlasting dynasty at the same time?
Purpose of the Beit HaMikdash – Ramban refers to the Mikdash as a "house of mercy". Radak similarly claims that it is a place of peace. As such, it could not be built by a man of war. Radak compares this to the prohibition against bringing an iron tool to the Mikdash since it s a vessel of war.
David Received Enough Glory
Hashem felt that David had received enough honor through his promotion to king and his many successes in battle. As such, it was not proper that he request also the glory of building the Mikdash, and it was preferable that his son be given that privilege.
Hashem's reply to David – Hashem's reply to David appears not to supply any rationale for His rejection of David's request, as He simply speaks of all the good He has done for David: choosing him as king, helping him in his conquests, and glorifying his name. Ralbag, however, suggests that these very points constitute Hashem's explanation. David had been given enough glory; it was time to share the wealth and allow someone else the honor of building the Mikdash.
Spilling of blood – This approach could maintain that when David tells Shelomo that he could not build the Mikdash because he had spilled too much blood and fought many wars, he truly believed that this was the reason. Since Hashem had only hinted to the real explanation, over the years David came up with his own (mistaken) rationale as to why his request was rejected.18
Shelomo to Chiram: "מִפְּנֵי הַמִּלְחָמָה אֲשֶׁר סְבָבֻהוּ" – Shelomo's words to Chiram might similarly represent only his own thoughts on the issue. When David told him that he was "a man of war" who "spilled much blood," Shelomo might have interpreted this to mean that being so busy with war left his father no time for domestic enterprises such as building the Mikdash.