Why was Shmuel afraid that Shaul would kill him for anointing David (Samuel 1 16:2)? If Hashem told Shmuel through prophecy to do this, why would Shaul (who was a righteous man) kill Shmuel for it (even if it seemed like a rebellion against the king of Israel)?
I think that Shmuel really was afraid that Shaul would kill him (Shmuel I 16:2):
יֹּאמֶר שְׁמוּאֵל אֵיךְ אֵלֵךְ וְשָׁמַע שָׁאוּל וַהֲרָגָנִי ס וַיֹּאמֶר יְהֹוָה עֶגְלַת בָּקָר תִּקַּח בְּיָדֶךָ וְאָמַרְתָּ לִזְבֹּחַ לַיהֹוָה בָּאתִי
And Samuel said, "How shall I go? For, if Saul hears, he will kill me." And the Lord said, "You shall take a heifer with you, and you shall say, 'I have come to slaughter (a sacrifice) to the Lord.'
As to your question "why would Shaul (who was a righteous man) kill Shmuel for it;" I don't think that's so much of a problem because even though Shaul was described earlier in sefer Shmuel as a good person (see Metzudas David to 9:2), that couldn't be relied on anymore because he was struggling with insanity and no longer in control, and became very paranoid in his later years, starting at around this time (Shmuel I 16:14):
וְרוּחַ יְהֹוָה סָרָה מֵעִם שָׁאוּל וּבִעֲתַתּוּ רוּחַ רָעָה מֵאֵת יְהֹוָה
And the spirit of the Lord departed from Saul, and an evil spirit from the Lord frightened him.