O you who believe!
Obey Allah and obey the Messenger and do not invalidate your deeds.
This made them fear that some sins could nullify their deeds."
It has also been reported from Ibn Umar, may Allah be pleased with him, that he said,
"We, the Companions of Allah's Messenger, used to think that good deeds would all be accepted, until Allah revealed,
أَطِيعُوا اللَّهَ وَأَطِيعُوا الرَّسُولَ وَلاَ تُبْطِلُوا أَعْمَالَكُمْ
(Obey Allah and obey the Messenger and do not invalidate your deeds). So we asked each other:
`What is it that can nullify our deeds'
So we said, `The major sins, great offenses that require admission into the Fire and immoral sins.'
But then Allah revealed,
إِنَّ اللَّهَ لاَ يَغْفِرُ أَن يُشْرَكَ بِهِ وَيَغْفِرُ مَا دُونَ ذَلِكَ لِمَن يَشَأءُ
Verily, Allah does not forgive joining partners with Him in worship, but He forgives except that to whom He wills. (4:48)
After this was revealed, we ceased saying that. We thereafter continued to fear for those who committed great sins and immoral sins and to have hope for those who did not."
Then, Allah commands His believing servants to obey Him and His Messenger, which would result in their happiness in this worldly life and the Hereafter. He also prohibits them from apostasy, because that would result in the nullification of their deeds.
Thus He says,
وَلاَ تُبْطِلُوا أَعْمَالَكُمْ
(and do not invalidate your deeds.) meaning, by apostasy.
Thus, Allah says after this,
إِنَّ الَّذِينَ كَفَرُوا وَصَدُّوا عَن سَبِيلِ اللَّهِ ثُمَّ مَاتُوا وَهُمْ كُفَّارٌ فَلَن يَغْفِرَ اللَّهُ لَهُمْ