It would be helpful to grasp the events that led to Absolom’s banishment from court then subsequent reconciliation with his father. These events are recorded in 2 Samuel 13 and 14. Absolom returned to Hebron, where David was first proclaimed King and where Absolom was born. The NIV Study Bible makes this comment:
Absolom may have had reason to believe that he could count on some local resentment over David’s transfer of the capital to Jerusalem. Hebron was also the site of an important sanctuary.
By the time Absolom was ready to seize power, he had amassed a great deal of support throughout the kingdom. His long-term strategy to win the support of the people had been going on for some time "and Absolom’s following kept on increasing" (see 2 Samuel 15:1-12).
A messenger came and told David, "The hearts of the men of Israel are with Absolom." Then David said to all his officials who were with him in Jerusalem, "Come! We must flee, or none of us will escape from Absolom. We must leave immediately, or we will move quickly to overtake us and bring ruin upon us and put the city to the sword" (2 Samuel 15:13-14).
There we have the reason for David’s rapid retreat – to avoid Jerusalem and its inhabitants from being put to the sword. David realised he simply couldn’t win this battle. "He who fights and runs away lives to fight another day." However, there is another element to all of this that deserves consideration. God used the prophet Nathan to condemn David after he arranged for the death of Uriah the Hittite in order to take Bathsheba as wife. The NIV Study Bible makes this comment:
"Now, therefore, the sword shall never depart from your house, because you despised me and took the wife of Uriah the Hittite to be your own" (2 Samuel 12:10). Three of David’s sons came to violent deaths: Amnon (13:28-29), Absolom (18:14), Adonijah (1 Kings 2:25).
"This is what the LORD says: Out of your own household I am going to bring calamity upon you. Before your very eyes I will take your wives and give them to one who is close to you, and he will lie with your wives in broad daylight" (2 Samuel 12:11). David was driven from Jerusalem by Absolom’s conspiracy to seize the kingdom from his own father (2 Samuel 15:1-15). Fulfilled at the time of Absolom’s rebellion (2 Samuel 16:22).
We should not overlook God’s sovereign will in all of this. The line to the birth of the Messiah was to come through David and Solomon. Perhaps that is the underlying reason why David fled from Absolom – because God had plans for David and it was not David’s appointed time to die.
Three months ago I did extensive research into the events leading up to the death of Joab, who used to be the commander of David’s army. Joab (David’s nephew) 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 kill Joab. Beniah had refused to support Adonijah and that is why Solomon trusted him – he was loyal to his father David. Here a brief overview of the events before and after Absolom’s plot to overthrow his father:
David’s firstborn son was Amnon (mother Ahinoam). Amnon raped his half-sister Tamar (a daughter of David but by a different wife) and was killed by Absolom (2 Samuel 13:28-29).
David’s second born son was Kileab (mother Abigail) but no further mention of him.
David’s third born son was Absolom (mother Maacah) but after rebelling against his father to seize the throne, was killed by Joab (commander of David’s army) but against David’s instructions (2 Samuel 18:12-15).
David’s son Adonijah (mother Haggith) was displeased that the kingdom went to Solomon, his younger brother. Benaiah (commander of Solomon’s army and faithful to David) killed Adonijah (1 Kings 2:25).
I realise that’s more information than you have requested, but it’s useful to understand the events that led up to the death of Absolom and the far-reaching consequences that resulted.
Edit – in response to the question “Why did his son hate him?” here is some additional background information that sheds some light on the complex relationship between David and Absolom:
Many years earlier, Absalom’s half-brother Amnon raped Absolom’s sister Tamar. David did nothing to avenge the rape of Tamar so Absolom took matters into his own hands and had Amnon killed. Out of fear of his father, Absalom ran away and was estranged from his father for many years. David did not hate Absolom and mourned his death. The events are recorded in 2 Samuel chapters 13-19.