According to this answer, if you accidentally start the weekday shemoneh esrei on Shabbos Cheshvan 7/December 5 or the first day of Pesach, you don't say ותן טל ומטר because the rest of the community isn't saying it yet/anymore.
Does the same apply to המלך המשפט? If you said המלך הקדוש correctly but then continued with the weekday shemoneh esrei on Rosh Hashana, Shabbos that immediately follows it, or Yom Kippur, and you realize in the middle of השיבה שפטינו, how do you end the bracha?