Surah Al-Ankaboot

29:10

وَمِنَ ٱلنَّاسِ مَن يَقُولُ ءَامَنَّا بِٱللَّهِ فَإِذَآ أُوذِىَ فِى ٱللَّهِ جَعَلَ فِتْنَةَ ٱلنَّاسِ كَعَذَابِ ٱللَّهِ وَلَئِن جَآءَ نَصْرٌۭ مِّن رَّبِّكَ لَيَقُولُنَّ إِنَّا كُنَّا مَعَكُمْ ۚ أَوَلَيْسَ ٱللَّهُ بِأَعْلَمَ بِمَا فِى صُدُورِ ٱلْعَٰلَمِينَ

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?

Tafsir 29:10

Amongst people is he who says: “I brought faith in Allah”. But when the disbelievers afflict him with harm due to his faith, he considers their torture the punishment of Allah, hence he renounces faith to conform with the disbelievers. And if you achieve help from your Lord, O Messenger, they will say: “We are with you in faith, O believers”. Does Allah not know best what is in the hearts of people, nothing of disbelief and faith they contain being hidden from Him? So how do you inform Allah of what is in their hearts when He knows better than them what they contain?