In this chapter, David hands down all of his grudges to Solomon, who then kills all of David's enemies.
This has got to be one of the least cheerful inheritances that Solomon received, when David starts telling him all of the people who are "still with you" and need to be dealt with. At this point, we can see that while David did not kill the people who resisted him, he did not forget his grudges either. Barzillai is rewarded again for his loyalty, but Joab and Shimei are condemned to violent deaths. Joab in particular was generally loyal to David, but David nevertheless marks him for death because Joab previously assassinated two innocent men during times of peace.
So one way to read this chapter is David passing down all of these grudges that he never got to address in his own lifetime. As a brief but interesting aside, this is exactly the kind of culture that perpetuates the present Israeli-Palestinian conflict as well. I can only imagine how many Israeli or Palestinian fathers out there telling their children the debt of violence that they owe to their enemies because of how such-and-such a person killed their grandfather 30 years ago. Not to say that historical violence should be forgotten or even that this is a uniquely Mideast thing, but this is exactly the kind of attitude that carries violence down from one generation to the next.
The other way to read this chapter is stated in verse 46: Solomon is "establishing" his kingdom by killing anyone who might resist him. This is a fairly standard (if grim) political tradition that is still practiced to this day. However dark it may be, it is effective: killing all of the people who have power to resist you is a very reliable way to shut down opposition.
Adonijah dies first. He goes to Bathsheba and asks for Abishag as a wife. Notice the immediate tension between these two figures when Bathsheba asks if he comes in peace (or in the alternative, if he comes in violence). The tension has a clear root as well, since Adonijah and Solomon are clearly rivals and Bathsheba is Solomon's mother. One might wonder why this is significant, but the answer is pretty clear. Abishag was essentially a consort to king David, so Adonijah marrying her would have the same political significance as marrying one of David's wives. In Israel's culture at this time, marrying your father's wife is basically staking out a claim to your father's authority and power. We saw this most recently when Absalom publicly slept with David's concubines to establish his authority over Israel (2 Samuel 16:22). Now Adonijah is seeking to do this, and strangely, he is asking Bathsheba for support.
What makes this story even stranger is that Bathsheba agrees and makes the request to Solomon. It is clearly a subversive request and while it is very dangerous for Adonijah to try this, it is even weirder that Bathsheba would support Adonijah's attempt to undermine Solomon. Nevertheless, Solomon is not going to be having any of this, and immediately orders Adonijah's death.
Abiathar is allowed to live because of his service to David. Verse 27 notes that this fulfilled the "word concerning the house of Eli", which is a reference to 1 Samuel 2 (if you can remember that far back) when "a man of God" came to Eli and told him that his house would be cursed because of the sins of his two sons. As far as I can tell, that passage doesn't specifically say that his descendants would be removed from the priesthood, but it's not much of a stretch to imagine the curse implying that. We also don't have any clear genealogies of the priesthood from Eli to Abiathar or Zadok, so I'm not sure who Zadok is a descendant of. All of these men are descendants of Aaron, but we can imagine that Eli is perhaps an older branch of the family and Zadok is from a younger branch, so with the removal of Abiathar the house of Eli no longer holds the priesthood, while Zadok maintains the line of Aaron through some other ancestor.
Out of the three people killed in this chapter (Adonijah, Joab and Shimei), Joab is the only one who hasn't committed a clear sin in this chapter. Because Shimei was forgiven by David, Solomon needed to find some other reason to kill him in accordance with David's request. Similarly, Solomon forgave Adonijah in the previous chapter. However, Joab was never forgiven for his crimes, so Solomon did not need any other reason to act against him.
As with Adonijah, Joab fled to the horns of the altar, pleading for clemency, and this time Solomon rejected his plea and killed him while he was still in the courtyard of the tabernacle. At long last, the command of the army falls to a different man, Jehoiada.
Lastly, Shimei is commanded to remain in Jerusalem for the rest of his life. This is reminiscent of David bringing Mephibosheth into his household to eat at his table, essentially preventing him from ever running off to start a revolt in some distant city. By remaining in Jerusalem, Shimei cannot rally opposition against David. However, in what we can only guess is a moment of forgetfulness, he goes off to Gath to retrieve some slaves and Solomon jumps at the opportunity to fulfill his pledge to get revenge on all of David's enemies. Shimei is killed, and with that, the last loose end from David's reign is tied up.
Now Solomon's rule is consolidated and we are about to enter a new era in Israel's history. This is basically the golden age of Israel's power when they are at their mightiest. We will shortly observe that Solomon does not walk in the same spirit as David, but it's almost like the afterglow of David's righteousness alone is enough to carry Solomon forward into a very successful kingship. I will expand on these topics in the chapters to come. For now though, David's life is over and it is time for us to shift our focus onto this emerging figure, king Solomon.