Miqdad (may Allah be pleased with him) narrated that he asked: O Messenger of Allah! What do you think if I encounter a disbeliever, and he fights me, then he strikes my hand with a sword and cuts it off, then he flees from me and takes refuge by a tree and says: "I have believed in Allah," so O Messenger of Allah! Should I kill him even after his declaration? The Messenger of Allah (peace be upon him) said: "Do not kill him." I said: O Messenger of Allah! He has cut off my hand, and he said this after cutting off my hand, so should I kill him? The Messenger of Allah (peace be upon him) said: "Do not kill him. The position you had before killing him is now his, and (if you kill him) your position will be what his was before he declared the testimony."
Hadith Referenceمسند الإمام الشافعي / كتاب القتل والقصاص والديات والقسامة / 1601
Hadith Takhrijاخرجه البخاري، الديات، باب قول الله تعالى ﴿ومن يقتل مؤمنا متعمدا....﴾ (6865)، ومسلم، الايمان، باب تحريم قتل الكافر بعد قوله لا اله الا الله (95)۔
It is narrated from Ubaidullah bin Adi bin Khiyar that a man whispered to the Messenger of Allah ﷺ; we did not know what he whispered to you ﷺ, until the Messenger of Allah ﷺ spoke loudly, and it became clear that he was seeking advice about killing a man from among the hypocrites. So the Messenger of Allah ﷺ said: "Does he not bear witness that there is no deity except Allah?" The man said: Yes, but his testimony will not benefit him. You ﷺ said: "Does he not perform prayer?" The man said: Yes, but his prayer is of no use to him. The Prophet ﷺ said: "These are the people whom Allah has forbidden me to kill."
Hadith Referenceمسند الإمام الشافعي / كتاب القتل والقصاص والديات والقسامة / 1602
Hadith Takhrijاخرجه البيهقي: 376/3 - واحمد: 5 / 433 - وعبد الرزاق (18688) وصححه ابن حبان۔