When this verse was revealed, "Whether you disclose what is within yourselves or conceal it, Allah will bring you to account for it. He forgives whom He wills and punishes whom He wills" [Baqarah 2:284], it grieved us deeply.We said, "One of us speaks within himself, and he will be brought to account for it. We do not know what will be forgiven and what will not."Then this verse was revealed afterward and abrogated it, "Allah does not burden a soul beyond its capacity. It will have what it has earned, and against it will be what it has wrought" [Baqarah 2:286].
حدثنا عبد بن حميد حدثنا عبيد الله بن موسى عن إسرائيل عن السدي قال
لما نزلت هذه الآية {إن تبدوا ما في أنفسكم أو تخفوه يحاسبكم به الله فيغفر لمن يشاء ويعذب من يشاء} الآية أحزنتنا قال قلنا يحدث أحدنا نفسه فيحاسب به لا ندري ما يغفر منه ولا ما لا يغفر فنزلت هذه الآية بعدها فنسختها {لا يكلف الله نفسا إلا وسعها لها ما كسبت وعليها ما اكتسبت}
Sources. Muslim also recorded it in the Book of Faith, in the chapter explaining how Allah overlooks passing thoughts and impulses of the heart when they do not settle... etc, hadith no. 126, from the hadith of Waki with the same wording.On this subject there is also a report from Abu Hurairah [Muslim, hadith no. 125].