The whole account needs to be understood, starting in 2 Samuel chapter 16:5-14 & 19:8 & 15-23 and taking up again in 1 Kings, the whole of chapter 2. Only then is the answer to your question clear. It all has to do with truly repenting before God and knowing God's forgiveness (as with David) or taking advantage of God's long-suffering and mercy till the point is reached when that ends and God's judgment falls (as with Shimei). This is about the difference between those two mindsets.
In 1 Samuel chapter 26, we learn of David's long-suffering and patient, respectful forbearance of the Lord's anointed, King Saul. Despite Saul trying to kill him, David would not kill Saul when the opportunity arose. He would not even say anything disrespectful about Saul. When David later became the Lord's anointed king, he knew full well what respect he was due, but he did not demand it. Rather, he had the patience to let people demonstrate unarguably whether they truly had respect for the king (and, hence, for God) or not.
When David fled from Absolom, he and his entourage passed over the brook Kidron. This turns out to be significant as Shimei later had to promise never to cross the Kidron valley, or he would die (1 Kings 2:37). They then went to Bahurim where Shimei started cursing David and throwing stones and dirt at the exhausted group. David prevented Abishai from decapitating Shimei by pointing out that his own son, Absolom, was trying to kill him - how much more Shimei the Benjamanite.
"Let him curse, because the Lord hath said unto him, Curse David. Let
him alone and let him curse, for the Lord hath bidden him. It may be
the the Lord will look on mine affliction, and that the Lord will
requite me good for his cursing this day" (2 Sam 16:11-12).
Whatever translation you were using said, "restore to me his covenant blessing" (instead of 'requite me good'.) That is not what the Hebrew text seems to say, but it is actually significant, because the matter of breaking a covenant is the key element many years later, when Shimei breaks the one he made with King Solomon. Going back to when David was still King and Shimei cursed him, this is an explanation I read in the book below:
“King David spared his life but said nothing about not imputing
iniquity and Shimei, being spared his life, pursued the matter no
further. No roaring seems to have occurred within Shimei that he found
it impossible to live his spared life without forgiveness. David, who
wrote Psalm 32, could not live without confessing his sins to the Lord
and without obtaining forgiveness, from the Lord. It seems enough for
Shimei that his life is spared and that he should continue on earth
and life his life without forgiveness. But his sin was still imputed.
It still belonged to him and still lay, heavily, to his account…
Many have a stirring or two about their sins. But that is not the roaring
that is felt when God Almighty presses his hand sore down upon a man,
crushing his inner parts till he is truly humbled, really penitent,
genuinely of a broken and a contrite heart, which condition God will
So Shimei had shrugged off the iniquity which was still imputed, willing to accept a covenant that depended on himself for
life. And, in due course, predictably, since his heart was wicked, he
broke it. Shimei had been granted space to repent. Time in which to
consider his ways. Days in which to meditate on a covenant which
required his obedience or, else, would require his death. But Shimei
must have had other things on his mind. His runaway servants, for
example.” Righteousness by N Johnstone pp58-60, Belmont Publications
The lessons in the protracted dealings of David, then Solomon, with this covenant-breaking, unrepentant Benjamanite - Shimei - teach us profound lessons about God's heavy hand, which should lead to genuine repentance, then entering the covenant with him. David wrote Psalm 32 which shows us David's mindset. And, conversely, it teaches us the way of sinners who will curse God's anointed, then take God's patience for granted, until finally they are lost to the covenant of grace. Eternally. Sobering lessons. But as David already understood all these things and was led by the Spirit of God, he said what he said, and did what he did, so that even after his death the lessons could come down the centuries, even to us.