Why does God command David to fight wars and then forbid him to build the temple? In other words, what was it about fighting the Lords wars that made him unfit to build the Temple? What do the ancient commentators say on this issue?
King David was not forbidden to build the temple because he was wrong to fight the wars. Even though he was right to fight and shed the blood, it was like building the altar with iron tools. It is also like someone who becomes tamei meis being unable to enter the temple even though he buried a meis mitzvah, which is a commandment.
Was King David wrong for waging so many battles? gives an interesting analogy.
A simple analogy: You are walking to a black tie dinner, and you pass by a muddy swamp. You notice someone sinking in the mucky water, screaming for help, so you jump in and save him. The guy you rescued thanks you profusely and goes on his way—but you won't really feel comfortable continuing on to the black tie dinner in your muddy, dripping suit. Chances are that security will escort you out if you do decide to make an appearance.
So does that mean that you now regret saving the drowning man?