The Rambam says a King must be anointed by a Sanhedrin, why did Shmuel seemingly go alone in secret?
The Rambam never says he has to be anointed in the presence of a Sanhedrin. I assume you refer to Melachim 1:3, where he writes – and uses Shaul as a proof! –
אֵין מַעֲמִידִין מֶלֶךְ בַּתְּחִלָּה אֶלָּא עַל פִּי בֵּית דִּין שֶׁל שִׁבְעִים זְקֵנִים וְעַל פִּי נָבִיא. כִּיהוֹשֻׁעַ שֶׁמִּנָּהוּ משֶׁה רַבֵּנוּ וּבֵית דִּינוֹ. וּכְשָׁאוּל וְדָוִד שֶׁמִּנָּם שְׁמוּאֵל הָרָמָתִי וּבֵית דִּינוֹ:
We only initially appoint a king on the word of a court of 70 elders and a prophet, like Yehoshua, appointed by Moshe and his court, and like Shaul and David, appointed by Shmuel and his court.
Apparently we have a tradition that he got it confirmed by his court before going to meet Shaul. While I’m unclear on where in the story this occurred, perhaps the Rambam is basing himself on Shmuel I:9:22:
וַיִּקַּ֤ח שְׁמוּאֵל֙ אֶת־שָׁא֣וּל וְאֶֽת־נַעֲר֔וֹ וַיְבִיאֵ֖ם לִשְׁכָּ֑תָה
And Shmuel took Shaul and his youth and brought them to his chamber
interpreting “his chamber” as a reference to his court. I have not seen anyone who says this, however.
The Rambam Melachim uMilchamot - Chapter 1 halacha 3 is talking about the normal situation in which a king must be appointed.
3 As an initial and preferred option, a king may be appointed only by a court of 70 elders, together with a prophet, as Joshua was appointed by Moses and his court, and as Saul and David, were appointed by Samuel of Ramah and his court.
Note that this implies that Shmuel actually convened his Sanhedrin as the Shofeit in charge of Bnai Yisrael to anoint Shmuel as king in front of the people that he had called together.
However, in Shmuel I 9:15 Shmuel is acting on the direct command of Hashem. As a result, when Shaul comes, Shmuel fulfills the prophecy and anoints Shaul as king.
15 Now, the Lord had revealed to Samuel one day before Saul's coming, saying,
16 "At this time tomorrow, I shall send to you a man from the land of Benjamin, and you shall anoint him to be a ruler of my people Israel, and he will save My people from the hand of the Philistines, for I have looked upon My people, for their cry has come to Me."
The Rambam implies that when Shmuel I 10:17 says
And Samuel called the people together unto God to Mizpah.
that the Sanhedrin was there with Shmuel. However, all of this was done at the specific command of Hashem.
Again with respect to David Hamelech, Shmuel acted on the express command of Hashem as we see in Shmuel I 16:1
1 And the Lord said to Samuel, "Until when are you mourning for Saul, when I have rejected him from reigning over Israel? Fill your horn with oil, and come, I shall send you to Jesse, the Bethlehemite, for I have seen for Myself a king among his sons."
And in verse 13
13 And Samuel took the horn of oil, and anointed him in the midst of his brothers. And a spirit of the Lord passed over David from that day forth, and Samuel arose and went to Ramah.
The implication was that this was the initial annointing at the command of Hashem and Shmuel was acting as the navi and head of the Sanhedrin. The Sanhedrin of Yehudah accepted him initially after Shaul died and the rest of the tribes accepted him later.