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! –
אֵין מַעֲמִידִין מֶלֶךְ בַּתְּחִלָּה אֶלָּא עַל פִּי בֵּית דִּין שֶׁל שִׁבְעִים זְקֵנִים וְעַל פִּי נָבִיא. כִּיהוֹשֻׁעַ שֶׁמִּנָּהוּ משֶׁה רַבֵּנוּ וּבֵית דִּינוֹ. וּכְשָׁאוּל וְדָוִד שֶׁמִּנָּם ...
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 ...