While David was on the run, Shimei cursed him and Abishai son of Zeruiah volunteered to kill him.
2 Samuel 16:10 But the king said, “What does this have to do with you, you sons of Zeruiah? If he is cursing because the Lord said to him, ‘Curse David,’ who can ask, ‘Why do you do this?’ ” 11David then said to Abishai and all his officials, “My son, my own flesh and blood, is trying to kill me. How much more, then, this Benjamite! Leave him alone; let him curse, for the Lord has told him to. 12It may be that the Lord will look upon my misery and restore to me his covenant blessing instead of his curse today.”
So according to David's logic, God could ask Shimei to curse David but then turn the curse into a blessing. Why was he over-reacting to Abishai who was on his side while being nice to Shimei who was against him?
Before David died, he instructed Solomon:
1 Kings 2:8“And remember, you have with you Shimei son of Gera, the Benjamite from Bahurim, who called down bitter curses on me the day I went to Mahanaim. When he came down to meet me at the Jordan, I swore to him by the Lord: ‘I will not put you to death by the sword.’ 9But now, do not consider him innocent. You are a man of wisdom; you will know what to do to him. Bring his gray head down to the grave in blood.”
Now David was unforgiving to Shimei. How to explain his mindset?