Sure Al-Ankaboot

29:10

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

Und unter den Menschen gibt es manchen, der sagt: "Wir glauben an Allah." Wenn ihm aber um Allahs willen Leid zugefügt wird, setzt er die Anfechtung durch die Menschen der Strafe Allahs gleich. Wenn jedoch Hilfe von deinem Herrn kommt, sagen sie ganz gewiß: "Wir sind ja mit euch gewesen." Weiß Allah denn nicht besser Bescheid über das, was'in den Brüsten der Weltenbewohner steckt?

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?