And of the people are some who say, "We believe in Allah ," but when one [of them] is harmed for [the cause of] Allah , they consider the trial of the people as [if it were] the punishment of Allah . But if victory comes from your Lord, they say, "Indeed, We were with you." Is not Allah most knowing of what is within the breasts of all creatures?
There are those who will be Muslims when all is good. Then when Allaah tests them, they apostate. They leave Islaam. Allaah tests the believers to see who is truthful, and who is a liar. These people were liars. Their claim that we are believers was only by means of their tongues. Their hearts were not firmly on Imaan. That is why when they were tested to see if they were truthful or liars, they were exposed as liars. They became apostates. They preferred this cursed life over the everlasting delights of the next world.
May Allaah keep us safe from being one of them.
Tafsir Ibn Katheer