2 Samuel 16:10 KJV
And the king said, What have I to do with you, ye sons of Zeruiah? so let him curse, because the LORD hath said unto him, Curse David. Who shall then say, Wherefore hast thou done so?
David gave three responses to Shimei's curses:
First, this was of the Lord.
Though what Absalom had done is wrong, and though Shimei's actions were not well motivated, David was very wise to ascribe this to the Lord and to let the Lord deal with it as he pleased. Andrew Murray said that God will only bless humility and humility can only be obtained through humiliation, therefore we ought to praise the Lord for those people who humiliate us. It will lead to our eventual blessing.
Second, his curse did not compare to what Absalom had done.
Who could possibly hurt David any worse. I am not sure this would make good counseling material, but there is nevertheless a truth in it.
Third, may be God would turn that evil into good.
Should David forgive Shimei, perhaps God would do some good thing for David. David has no idea where God might eventually take this trial. If he rewards good for the evil of Shimei, he can expect that in some way God will reward to David good for Shimei's evil.
Vengeance always belongs to the Lord. We have no good reason to ever try to get even but to instead seek the Lord's will in all things. He will do what is good. Always.