Some people asked the Messenger of Allah ﷺ, "Messenger of Allah, will we be held accountable for what we did during the days of ignorance?"He replied, "Whoever among you does well in Islam will not be held accountable for it, but whoever does evil will be held accountable for his deeds both in the days of ignorance and in Islam."
قال أناس لرسول الله ﷺ: يا رسول الله، أنؤاخذ بما عملنا في الجاهلية؟ قال: أما من أحسن منكم في الإسلام فلا يؤاخذ بها، ومن أساء أخذ بعمله في الجاهلية والإسلام.
Bukhari narrated it in the chapter on calling apostates and obstinate rebels to repentance and fighting them (6921), and Muslim in the Book of Faith (120:189), both through the route of Mansur, from Abu Waail, from Abdullah bin Masud, who mentioned it.Reconciling the two hadiths, the first hadith indicates steadfastness in Islam, while the second contains an allusion to apostasy or shirk. Whoever apostatizes or commits shirk is held accountable for the evil deeds he did both in pre-Islamic ignorance and in Islam. Bukhari mentioned it in the chapter on calling apostates to repentance.