Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:4:17

The repentance accepted by Allah is only for those who do wrong in ignorance ˹or carelessness˺ and then repent soon after. It is those to whom Allah will turn in forgiveness, and Allah is ever Knowing and Wise.  

The repentance that God accepts, that is, the one which He has prescribed for Himself to accept, out of His bounty, is only of those who do evil, an act of disobedience, in ignorance (bi-jahālatin, a circumstantial qualifier, in other words, ‘they are ignorant’ while they are disobeying their Lord); then repent shortly thereafter, before the last gasps of death; God will relent to those, He will accept their repentance. And God is ever Knowing, of His creatures, Wise, in what He does with them.
القرآن:٤:١٧

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

{إنما التوبة على الله} أي التي كتب على نفسه قبولها بفضله {للذين يعملون السوء} المعصية {بجهالة} حال أي جاهلين إذا عصوا ربهم {ثم يتوبون من} زمن {قريب} قبل أن يغرغروا {فأولئك يتوب الله عليهم} يقبل توبتهم {وكان الله عليما} بخلقه {حكيما} في صنعه بهم.