Politics. Power. War. Family. This is my take:
Joab would have pulled the "patriot" defense, and would likely have got away with his deed: 2Sam 3:25 Thou knowest Abner the son of Ner, that he came to deceive thee, and to know thy going out and thy coming in, and to know all that thou doest."
If David sought Joab's conviction and execution, for murder and treason, he could have (from the earthly viewpoint), winning or losing the judgment might have lost the union of the people he had just achieved, chiefly by losing the Judahites. If he acted similar to Saul, and just summarily executed Joab on his own prerogative as supreme dictator, he would have undermined his position morally. As it was, Joab's twisted vengeance nearly cost the unity anyway, and it took a public mourning by David (vv 31, 32, 37) to redress what had been so long in the making and nearly undone.