O you who have believed, when you go forth [to fight] in the cause of Allāh, investigate; and do not say to one who gives you [a greeting of] peace, "You are not a believer,"1 aspiring for the goods of worldly life; for with Allāh are many acquisitions. You [yourselves] were like that before; then Allāh conferred His favor [i.e., guidance] upon you, so investigate. Indeed Allāh is ever, of what you do, Aware.
Translation: Saheeh International (English)
1 Do not assume that he pretends Islām merely in order to save himself, for he may be sincere in faith.
O you who have faith in Allah and follow His Messenger, when you go out to fight in Allah’s path, be sure about the case of those you are fighting. Do not say to the person who displays something indicating that he is a believer, ‘You are not a believer! You only displayed Islam out of fear for your life and wealth’; so that you then kill him in order to get the trivial goods of the world, such as the booty you acquire from this person after killing him. Yet Allah has much provision that is better and greater than this. In the past you were also like this person: hiding your faith from the people. Then Allah favoured you with Islam and protected your lives. So be careful, as Allah knows well what you do. Nothing is hidden from Him and He will reward you for your actions.