Joab was the commander of David's armies. Before we can understand why he killed Absolom we need to understand what was going on within the royal household:
David’s firstborn son was Amnon (mother Ahinoam), who raped his half-sister Tamar (a daughter of David but by a different wife).
David's second son was Kileab (mother Abigail), but nothing else is recorded about him - perhaps he died.
Absolom was David’s third son (mother Maacah), and he was Tamar’s brother.
Absolom killed Amnon then tried to steal the throne from his father. Joab was commander of David’s armies and he killed Absolom, but against David’s wishes.
Adonijah was David’s fourth son (mother Haggith) and he also tried to steal the throne from his father David.
Joab (David’s nephew) then killed his cousin Amasa after David replaced Joab with Amasa as commander of his armies. Joab supported Adonijah’s bid for David’s throne.
Before David died, and after David had anointed his son Solomon as king, David got Solomon to promise he would have Joab killed. David had never forgiven Joab for killing Absolom (against his express instructions). Solomon entrusted Beniah, who was now commander of David's armies, and who had refused to support Adonijah's bid for the throne. Beniah was loyal to his father David.
Looks like Joab killed Absolom because he supported Adonijah as the next heir to David's throne. And Joab wasn't best pleased when he lost his position as one of David's mighty men. However, he didn't reckon with God's plans to put Solomon on the throne, and through him, would come the promised Messiah.
The words of Robert Burns spring to mind - something about the best-laid plans of mice and men going astray.
Research material into David’s wives and sons:
2 Samuel 2:2 – David’s wives: Ahinoam of Jezreel (Saul’s widow); Abigail (widow of Nabal of Carmel; 2 Samuel 3:2-5 – Maacah (daughter of Talmai, king of Geshur); Eglah. It is supposed that David also married Haggith and Abital.
2 Samuel 3:2-5 - Sons born to David in Hebron:
Amnon the son of Ahinoam of Jezreel (David’s wife)
Kileab the son of Abigail the widow of Nabal of Carmel (David’s wife)
Absolom the son of Maacah daughter of Talmai king of Geshur (David’s wife)
Adonijah the son of Haggith
Sephatiah the son of Abital
Ithream the son of David’s wife Eglah
1 Chronicles 3:1-4 repeat the six sons born to David in Hebron, where he reigned for seven years and six months. (Kileab is called Daniel) Then verses 5-9 list the sons born to David when he reigned in Jerusalem for 33 years (apart from his sons by his concubines):
Shammua, Shobab, Nathan and Solomon (mother Bathsheba)
Ibhar, Elishua, Eliphelet, Nogah, Nepheg, Japhia, Elishama, Eliada, Eliphelet, and their sister Tamar.
More about Adonijah's unsuccessful bid for power in this article: https://www.gotquestions.org/Solomon-Adonijah-Abishag.html