How was the Mekoshesh, the man found gathering wood on Shabbat in Sh'lach L'cha, given the death penalty if the punishment wasn't known yet, so he couldn't have been warned, being that the warning must contain the exact punishment for that act?
Rashi and Rav Hirsch explain that Hashem had already commanded that he was subject to the death penalty, but they did not yet know the precise manner of the punishment.
They put him under guard, since it was not specified what was to be done to him.
since it was not specified what was to be done to him: With which method he should be executed. But they did know that one who desecrates the Sabbath is put to death. — [Sifrei Shelach 57]
Rav Hirsch explains that
But here: כי לא פרש מה יעשה לו, that it was a capital crime punishable by death was in no doubt, מחלליה מות יומת (Exodus XXXI,14) had already been proclaimed, the only doubt was מה יעשה לו, which form of death was to be administered. יודע היה משה רבינו שהמקושש במיתה שנאמר מחלליה םות יומת אלא לא היה יודע באיזה מיתה נהרג (Sanhedrin 78b). Nevertheless, the התראה was legally sufficient, for all that is required is שהתרו בו סתם that he is told that what he does is a capital crime (Ibid 80b). But in the opinion of רב יהודה any התראה is incomplete if the actual form of the death to which he is liable is not specified to the criminal, then the killing of the מקושש was a special case, an הוראת שעה dictated directly by Hashem and cannot be used as an example for the general practice.
הוַיֹּ֤אמֶר יְהֹוָה֙ אֶל־משֶׁ֔ה מ֥וֹת יוּמַ֖ת הָאִ֑ישׁ רָג֨וֹם אֹת֤וֹ בָֽאֲבָנִים֙ כָּל־הָ֣עֵדָ֔ה מִח֖וּץ לַמַּֽחֲנֶֽה
This is addressed by Sanhedrin 80b. It’s a dispute to begin with whether the particular form of death needs to be specified in the warning:
תניא ושאר חייבי מיתות שבתורה אין ממיתין אותן אלא בעדה ועדים והתראה ועד שיודיעוהו שהוא חייב מיתת ב"ד רבי יהודה אומר עד שיודיעוהו באיזה מיתה הוא נהרג
We taught in a Braisa: For all others that make liable to death from the Torah, we don’t kill them except with a court, witnesses, warning, and until they warn him that he’s liable to death. R’ Yehudah says: until they tell him with which death he will be killed.
The Gemara continues, explaining the Mekoshesh:
ת"ק יליף ממקושש ורבי יהודה אומר מקושש הוראת שעה היתה:
The Tanna Kamma learns this from the Mekoshesh, and R’ Yehudah says, the Mekoshesh was a hora’as sha’ah.
According to the Tanna Kamma, just as the Mekoshesh was warned that he’d be put to death but not which one, so, too, all warnings for the death penalty. According to R’ Yehudah, that case was uniquely instructed by Hashem.
Now, they did know that one who violates Shabbos is liable to death; the only question was which one. To quote the Gemara ibid. 78b:
תניא יודע היה משה רבינו שהמקושש במיתה שנאמר (שמות לא, יד) מחלליה מות יומת אלא לא היה יודע באיזו מיתה נהרג שנאמר (במדבר טו, לד) כי לא פורש
It was taught in a Braisa: Moshe knew that the Mekoshesh was to be put to death, as it says, “One who violates [Shabbos] will be put to death,” but he didn’t know with which death he should be killed, as it says, “It was not explained.”