The repentance accepted by Allāh is only for those who do wrong in ignorance [or carelessness] and then repent soon [after].1 It is those to whom Allāh will turn in forgiveness, and Allāh is ever Knowing and Wise.
Translation: Saheeh International (English)
1 Scholars have also interpreted "soon" to mean before death.
Allah only turns in mercy and forgiveness to those who commit disobedience and overstep the limits out of foolishness and impulse, and who repent to Allah asking for His forgiveness before the time of their death. Allah forgives these people, by overlooking their disobedience. Allah knows the circumstances of people, and is Wise in His decree and sacred laws.