Sure Al-Baqara

2:54

وَإِذْ قَالَ مُوسَىٰ لِقَوْمِهِۦ يَٰقَوْمِ إِنَّكُمْ ظَلَمْتُمْ أَنفُسَكُم بِٱتِّخَاذِكُمُ ٱلْعِجْلَ فَتُوبُوٓا۟ إِلَىٰ بَارِئِكُمْ فَٱقْتُلُوٓا۟ أَنفُسَكُمْ ذَٰلِكُمْ خَيْرٌۭ لَّكُمْ عِندَ بَارِئِكُمْ فَتَابَ عَلَيْكُمْ ۚ إِنَّهُۥ هُوَ ٱلتَّوَّابُ ٱلرَّحِيمُ

Und als Musa zu seinem Volk sagte: "O mein Volk, ihr habt euch selbst Unrecht zugefügt, indem ihr das Kalb (zum Gegenstand der Anbetung) genommen habt. Bereut nun vor eurem Erschaffer und tötet dann (die Schuldigen unter) euch selbst! Dies ist besser für euch vor eurem Erschaffer!" Und da nahm Er eure Reue an; Er ist ja der Reue-Annehmende und Barmherzige.

Tafsir 2:54

Also, remember that Allah’s allowing you to ask His forgiveness for worshipping the calf, when Moses (peace be upon him) told you that you had wronged yourselves by taking the calf as a god and worshipping it, were from the blessings of Allah. Moses told you to ask for forgiveness and repent to your Creator by some of you killing others, because turning to Him in this way was better for you than persisting in disbelief, which would lead to an eternity in the fire of Hell. So, you did this with Allah’s approval, and He forgave you, for He is Forgiving and Merciful with His servants.