In this past weeks parsha we had the dinim of עיר הנדחת. The Rambam in Hilchos Avoda Zara (4:6) writes a very difficult din. He writes that if the people do teshuva the city no longer has a din of עיר הנדחת. The Raavad there asks that we don't find that teshuva ever helps by a punishment of בית דין.
Many acharonim ask why is this so? Why doesn't teshuva help to save a person from a punishment of בית דין? There are many answers, I will mention 2.
The Chida writes that in theory Teshuva would help, but the בית דין can never ascertain whther a person really did teshuva. Only Hashem can, and therefore theבית דין cannot take teshiva into account.
A more fundamental answer is based on the following. We can ask how can teshuva work? After all normally we say לא אתי דיבור ומבטל מעשה, words cannot wipe out actions. The answer is that teshuva does not work with the notmal principles, teshuva is not of this world, in fact, Chazal state that teshuva preceded creation. Therefore, בית דין cannot take into account teshuva because it is not part of the system of this world.
This all strengthens the Raavad's question.
RYBS (printed in קובץ חידושי תורה) explained the Rambam as follows. When the Rambam writes that if they do teshuva they no longer have a din of עיר הנדחת he doesn't mean that the guilty go scot free. He means that the city is no longer an עיר הנדחת and all the various dinim of עיר הנדחת don't apply, however, those individuals who worshipped avoda zara are punished as individuals. Why is this so? RYBS explained that the gemara (based on the pesukim) says that the people of an עיר הנדחת are בני בליעל, reshaim who have no chelek in olam haba. The Rambam understood this as part of the definition of an עיר הנדחת, that the people need to be reshaim who have no chelek in olam haba. Therefore, if they do teshuva, it doesn't absolve them and prevent punishment but takes away the חלות שם of עיר הנדחת because they can no longer be called בני בליעל, Since, בני בליעל is part of the definition of עיר הנדחת the city no longer qualifies, however, they are punished as individuals.