Surah An-Nisa, ayah 17

4:17

إِنَّمَا ٱلتَّوۡبَةُ عَلَى ٱللَّهِ لِلَّذِينَ يَعۡمَلُونَ ٱلسُّوٓءَ بِجَهَٰلَةٖ ثُمَّ يَتُوبُونَ مِن قَرِيبٖ فَأُوْلَٰٓئِكَ يَتُوبُ ٱللَّهُ عَلَيۡهِمۡۗ وَكَانَ ٱللَّهُ عَلِيمًا حَكِيمٗا ١٧

Innamat-tawbatu 'alallāhi lilladhīna ya'malūnas-sū'a bijahālatin thumma yatūbūna min qarībin fa ulā'ika yatūbullāhu 'alayhim wakānallāhu 'alīman hakīmā

The repentance accepted by Allāh is only for those who do wrong in ignorance [or carelessness] and then repent soon [after].172 It is those to whom Allāh will turn in forgiveness, and Allāh is ever Knowing and Wise.

Footnotes

172 Scholars have also interpreted "soon" to mean before death.