"Indeed I have sinned" (Joshua 7:20). Our rabbis taught: when the condemned man was about ten cubits from the place of stoning, they would say to him, "Confess," for it is the way of all who are put to death to confess, since everyone who confesses has a share in the World to Come. And if he does not know how to confess, they say to him, "Say: may my death be an atonement for all my sins." For so we find with Achan, that Joshua said to him, "My son, give now glory to the LORD, the God of Israel, and make confession to Him" (Joshua 7:19), "and Achan answered Joshua and said, Indeed I have sinned" (Joshua 7:20). And how do we know that his confession atoned for him? As it is said, "And Joshua said, Why have you troubled us? The LORD shall trouble you this day" (Joshua 7:25) — this day you are troubled, but you are not troubled in the World to Come.
Achan Confesses and Wins a Share in the World to Come
Yalkut Shimoni on Nach 18:11
אמנה אנכי חטאתי (יהושע ז, כ). שנו רבותינו היה רחוק מבית הסקילה כעשר אמות אומרים לו התודה שכן דרך המומתין מתודין שכל המתודה יש לו חלק לעולם הבא, ואם אינו יודע להתודות אומרים לו אמור תהא מיתתי כפרה על כל עונותי, שכן מצינו בעכן שאמר לו יהושע בני שים נא כבוד לה' ותן לו תודה ויען עכן את יהושע ויאמר אמנה אנכי חטאתי, ומנין שכפר לו וידויו שנאמר ויאמר יהושע מה עכרתנו יעכרך ה' היום הזה, היום הזה אתה עכור ואי אתה עכור לעוה"ב: