To deal with Joab and Shimei. Joab murdered two commanders in peacetime, so "do not let his gray head go down to Sheol in peace" (1 Kings 2:5-6). Shimei cursed David on the road out of Jerusalem, and David had sworn not to kill him; now, "you must bring his gray head down with blood to Sheol" (2:8-9). Between them comes one kindness: loyalty to the sons of Barzillai, who stood by David when he fled from Absalom (2:7).
Sheol is the underworld, the place the dead were thought to go. David's oath to Shimei bound David alone, and the note in the New Oxford Annotated Bible says Solomon is not bound by it. The text gives David forty years as king (2:11); Solomon is later given forty too, a round number for a long time.
Learn the Bible.
Not just the stories, but the history, authorship, and scholarship behind it.