عَنِ ابْنِ مَسْعُودٍ رضى اللّٰه عنه قَالَ قَالَ رَجُلٌ يَا رَسُولَ اللّٰه أَنُؤَاخَذُ بِمَا عَمِلْنَا فِي الْجَاهِلِيَّةِ قَالَ مَنْ أَحْسَنَ فِي الإِسْلَامِ لَمْ يُؤَاخَذْ بِمَا عَمِلَ فِي الْجَاهِلِيَّةِ، وَمَنْ أَسَاءَ فِي الإِسْلاَمِ أُخِذَ بِالأَوَّلِ وَالآخِرِ.
Hazrat Ibn Mas‘udra narrated that, “A man asked [the Holy Prophetsa], ‘O Allah’s Messengersa, will we be held accountable for what we did during al-Jahiliyyah [i.e., the pre-Islamic period of ignorance]?’ He responded, ‘Whoever performs good deeds in Islam will not be held accountable for what they did during al-Jahiliyyah. However, whoever does evil deeds in Islam will be held accountable for both their past and present deeds.’”
(Sahih al-Bukhari, Kitab istitabati l-murtaddina wa l-mu‘anidina wa qitalihim, Bab ithmi mun ashraka billahi wa uqubatihi fi d-dunya wa l-akhirah, Hadith 6921)