Joab was a loyal captain of King David. However he conspired with Adonijah. (1 Kings 2:28). Was there bitterness in his heart toward David because of the recent killing of Absalom? Or did Joab think that David would again humiliate his army? (2 Samuel 19:1-7).
David's first and third sons, Amnon and Absalom, were dead. His second son, Chileab, was nowhere to be found after mention of his birth in 2 Samuel 3.3. Adonijah was David's eldest surviving son.
With David near the end of his life, Adonijah apparently believed it was time to accede the throne. To help stabilize his accession, Adonijah garnered the support of Joab and Abiathar, two men who had been allies of David.
We see Joab butt heads with David over political and personal affairs more than once in 2 Samuel. When David showed mercy on former enemies, Joab worked against David's decision and killed them: Abner for revenge, and Amasa for taking his job as commander of Israel's army. When David mourned the death of Absalom, Joab saw it as weakness and subtly warned him to stop lest 'someone' turn against him. When David spurned Joab's objections to taking a census of Israel, Joab thought David's decision was 'abhorrent' (1 Chronicles 21.6).
The portrait of Joab in 2 Samuel comes across as a man who is vengeful, resentful, even opportunistic, but still loyal to the House of David. Joab butts heads with David, but he never betrays his king.
First Kings 1.6 outlines what made Adonijah's claim to the throne appealing: Adonijah had never displeased David before, and Adonijah was next in line to rule. When Adonijah went to Joab to secure support for the transition of power, it is easy to suspect Joab was eager for the change.
Only after Adonijah's public coronation does Solomon show up claiming to be David's true successor.
From Joab's perspective, Solomon would appear to be the illegitimate claimant to the throne, not Adonijah. Solomon's attempts to take the throne would be seen by Joab as a coup, similar to what had happened years earlier with David's other son, Absalom.