And remember Moses said to his people: “O my people! Ye have indeed wronged yourselves by your worship of the calf: So turn (in repentance) to your Maker, and slay yourselves (the wrong-doers); that will be better for you in the sight of your Maker.” Then He turned towards you (in forgiveness): For He is Oft-Returning, Most Merciful.
The following excerpt is taken from “Maariful Quran” vol 1 pg. 214:
This verse describes the special mode of offering their Taubuh
(repentance) which was prescribed for the Israelites in this situation,
— that is to say, those who had not indulged in the worship of the
golden calf should execute those who had. Similarly, in the Islamic
~hari’ah too, certain major sins necessarily entail capital punishment
even when the sinner has offered this Taubah — for example, life in
return for a life in the case of intentional homicide, or death by stoning
in the case of adultery established through proper evidence.
Then the Israelites acted upon this divine commandments, they
became worthy of receiving the mercy and favour of Allah in the other
Shafi, Muhammad (2008). Maariful Quran. (Vol .1 pg. 214) http://www.islamicweblibrary.com/wp-content/uploads/2020/04/maarif-volum1-english.pdf