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." ט. וְעַתָּה אַל
תְּנַקֵּהוּ כִּי אִישׁ חָכָם אָתָּה וְיָדַעְתָּ אֵת אֲשֶׁר תַּעֲשֶׂה
לּוֹ וְהוֹרַדְתָּ אֶת שֵׂיבָתוֹ בְּדָם שְׁאוֹל:

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?

Came down to meet me - that I may absolve him and I swore that I would not put him to death, [and] although I swore that I would not put him to death, he is to be put to death, and [in order] to keep my oath you shall not put him to death, until you find him cause and iniquity and turn it so that he comes to an iniquity, so you have a judgment to put upon him, in order to put him to death for you are a wise man and will find him a cause.

And now - meaning to say I swore and absolved him and now if he sins to you hold him not guiltless, for you are a wise man, and you will surely know what you ought to do to him to test him if he obeys the king appropriately and if you find wrong in him and you shall bring his hoary head down to the grave with blood and do not absolve him.

According to RaDaQ's interpretation David's absolution and oath did not remove from Shime'i the requirement of death for his actions, but only David's ability to carry it out( or Shlomo's ability to do so in his name). So, he instructed Shelomo to find a way to do so.

According to Malbim's interpretation, Shime'i was not to be put to death( for his crime against David), but his loyalty was not to be trusted, and David forgiving him was not to be considered a precedent for any subsequent crimes. So, he instructed Shelomo to test Shime'i, and only if he found him guilty to execute him, and to not absolve him.

The Targum to Esther 2:5 says that Mordechai was descended from Shimei ben Geira, as was Esther, and that David's attitude toward Shimei initially was due to his prophetic knowledge of the two saviors of Israel that were to come from him. Once David saw that Shimei had stopped having children, he knew that Mordechai and Esther were accounted for, so he had Solomon kill Shimei.