Melachim I 2:8-9 reads
And, behold, there is with you Shimei the son of Gera the Benjamite of Bahurim, who cursed me with a grievous curse on the day when I went to Mahanaim, and he came down to meet me at the Jordan, and I swore to him by the Lord, saying, 'I will not put you to death with the sword.' ח. וְהִנֵּה עִמְּךָ שִׁמְעִי בֶן גֵּרָא בֶן הַיְמִינִי מִבַּחֻרִים וְהוּא קִלְלַנִי קְלָלָה נִמְרֶצֶת בְּיוֹם לֶכְתִּי מַחֲנָיִם וְהוּא יָרַד לִקְרָאתִי הַיַּרְדֵּן וָאֶשָּׁבַע לוֹ בַיהֹוָה לֵאמֹר אִם אֲמִיתְךָ בֶּחָרֶב:
And now hold him not guiltless, for you are a wise man, and you will surely know what you ought to do to him, and you shall bring his hoary head down to the grave with blood." ט. וְעַתָּה אַל תְּנַקֵּהוּ כִּי אִישׁ חָכָם אָתָּה וְיָדַעְתָּ אֵת אֲשֶׁר תַּעֲשֶׂה לּוֹ וְהוֹרַדְתָּ אֶת שֵׂיבָתוֹ בְּדָם שְׁאוֹל:
However when this episode actually occurred David HaMelech's response to Shimei seems quite different:
And Abishai the son of Zeruiah said to the king, "Why should this dead dog curse my lord the king? let me go over, I beg you, and remove his head." ט. וַיֹּאמֶר אֲבִישַׁי בֶּן צְרוּיָה אֶל הַמֶּלֶךְ לָמָּה יְקַלֵּל הַכֶּלֶב הַמֵּת הַזֶּה אֶת אֲדֹנִי הַמֶּלֶךְ אֶעְבְּרָה נָּא וְאָסִירָה אֶת רֹאשׁוֹ:
And the king said, "What is it between me and you, sons of Zeruiah? So let him curse, because the Lord has [surely] said to him, 'Curse David'; who then shall [have the right to] say, 'Why have you done so'?" י. וַיֹּאמֶר הַמֶּלֶךְ מַה לִּי וְלָכֶם בְּנֵי צְרֻיָה כֹּה יְקַלֵּל כִּי יְהֹוָה אָמַר לוֹ קַלֵּל אֶת דָּוִד וּמִי יֹאמַר מַדּוּעַ עָשִֹיתָה כֵּן:
So if David HaMelech objected to to punishing Shimei then, why did he later on tell Shlomo to punish him?