Imagine the day when you need everything that counts to be there for you, knowing that you have done so many ‘good’ deeds during your lifetime, and when push comes to shove:
“On the Day they will see the angels, no glad tidings will there be for the Wrongdoers that day. And they (angels) will say: "All kinds of glad tidings are forbidden for you," and We shall turn to whatever deeds they did, and We shall make such deeds as scattered floating particles of dust.”
"Say (O Muhammad): "Shall We tell you the greatest losers in respect of (their) deeds? Those whose efforts have been wasted in this life while they thought that they were acquiring good by their deeds! They are those who disbelieve the signs of their Lord and the Meeting with Him (Hereafter). So their works are in vain, and on the Day of Resurrection, We shall not give them any weight.”
Shaikh Abu Bakr Jabir al-Jazaairi (rahimahullah) said concerning these verses:
“Included in this are every polytheist, Jew, Christian, Haruriyah, those who perform actions based on riya’ (showing off) and everyone who does good deeds thinking that he has done well but his actions will be nullified due to corrupt belief, riya’, or actions not according to the syari’ah of Allah, like the different types of major bid’ah.”
[Nahr al-Khair ‘ala Aysar at-Tafaasir, pg. 288]
These verses stress the importance of having pure intentions, performing good deeds for the sake of Allah. Pure intentions will not be easy without strong faith in Allah and the Last Day, hence in Sura al-Kahf, Allah mentioned that their good deeds will be loss due to their disbelief of Allah and the Hereafter, or due to the weakness in faith that they perform good deeds only for worldly benefits.