Usāmah ibn Zayd (may Allah be pleased with him) reported: The Messenger of Allah (may Allah's peace and blessings be upon him) sent us to Al-Huraqah, a sub- tribe of Juhaynah, and we attacked them in the morning at their springs. A man from the Ansār and I chased one of their men, and when we attacked him he said "there is no god but Allah". The Ansāri man held back from him but I stabbed him with my spear until I killed him. When we arrived in Madīnah, the news of this incident reached the Prophet (may Allah's peace and blessings be upon him) so he said to me: "O Usāmah, you killed him after he had said there is no god but Allah?" I said: "O Messenger of Allah, he only said it to protect himself." He repeated: "You killed him after he had said there is no god but Allah?" He kept repeating it until I wished I had not embraced Islam before that day.
In another narration: "So the Messenger of Allah (may Allah's peace and blessings be upon him) said: 'Did he say there is no god but Allah and yet you still killed him?' I said: 'O Messenger of Allah, he only said it out of fear of the weapon!' He said: 'Did you split open his heart to know whether or not he meant it?' He continued saying it over and over again until I wished I had embraced Islam only that day."
Jundub ibn ‘Abdullāh (may Allah be pleased with him) reported: The Messenger of Allah (may Allah's peace and blessings be upon him) sent an army of the Muslims to a tribe of idolaters. The two sides met (in combat). There was one of the idolaters who, whenever he wanted to aim for one of the Muslims, he went straight for him and killed him. A man from the Muslims was waiting for a chance to attack him while he was unaware. We heard that it was Usāmah ibn Zayd. When he (the Muslim man) raised his sword, the idolater said "there is no god but Allah", but he killed him. A man came to the Messenger of Allah (may Allah's peace and blessings be upon him) with news of the victory, and he asked him (about the battle) so he informed him of everything including what that man (Usāmah) had done. The Messenger of Allah (may Allah's peace and blessings be upon him) summoned him and asked him: "Why did you kill him?" He said: "O Messenger of Allah, He struck many of the Muslims and killed so and so of them –and he named a group. I attacked him and when he saw the sword he said there is no god but Allah." The Messenger of Allah said: "Did you kill him?" Usasmah said: 'Yes.' The Messenger of Allah said: "What will you do with (his statement) there is no god but Allah when it comes on the Day of Judgment?" Usāmah said: "O Messenger of Allah, seek forgiveness for me!" He said: "And what will you do with there is no god but Allah when it comes on the Day of Judgment?" He added nothing, but kept repeating: "What would you do with there is no god but Allah when it comes on the Day of Judgment?"
Authentic hadith -
Muslim with its two versions - Narrated by Bukhari & Muslim