Their punishment was (14:35) במדבר הזה יתמו ושם ימותו, ‘In this desert, they will perish, and they will die there.’
The Chasam Sofer zt’l (תורת משה ד"ה במדבר) explains that יִתַּמּוּ hints that they would return to their temimus, their perfection, and that will rectify their sin.
He explains that in sefer Devarim (9:2), Moshe announced to the nation the great powerful nations that live in Eretz Canaan, but this time, it didn’t frighten them. Moshe told them, עם גדול ורם בני ענקים, ‘A large nation… the children of giants…’ but they weren’t afraid.
The Chasam Sofer explains, ‘Moshe wasn’t concerned they would be frightened and that they won’t want to go into Eretz Yisrael because by that time Moshe was already their leader for forty years, which is when students perceive the lessons of their teacher (as Rashi writes Devarim 29:3). And when one understands Moshe’s teachings and he understands the holiness of Eretz Yisrael and the holiness of each Yid’s neshamah, he is moser nefesh and gives away all his money even just to see Eretz Yisrael.
‘The generation of the meraglim didn’t attain that perception yet. Therefore, they said, לו מתנו במצרים או במדבר הזה, ‘If only we would die in Egypt or in this desert.’ Dying in the desert wasn’t a punishment for them because that is what they requested: לו מתנו, ‘If only we could die in the desert.’ Each person lived until he was sixty, and by that time, they attained their sheleimus, temimus, and perfection. At that age, they perceived the holiness of Eretz Yisrael, and they had immense distress knowing that they would die in the desert and not go up to Eretz Yisrael. This is the meaning of the pasuk, במדבר הזה יתמו, you will live in this desert until you attain temimus and perfection, and you will perceive the holiness of Eretz Yisrael, ושם, and after you attain perfection, ימותו, you will die, and you will be upset that you are dying [before going into Eretz Yisrael]. Their regret will be their punishment, and thereby they will merit Olam HaBa.’