Sayyiduna Ibn Abbas (may Allah be pleased with them both) narrates that Abdullah bin Abdullah bin Ubayy was told by his father (Abdullah bin Ubayy): O my son, ask the Messenger of Allah (peace and blessings be upon him) for one of his garments for me, in which I may be shrouded, and ask him to lead my funeral prayer. So Abdullah (bin Abdullah) said: O Messenger of Allah, you know the standing of Abdullah (bin Ubayy); he has instructed me to ask you for a garment in which he may be shrouded, and that you lead the funeral prayer over him. So he (peace and blessings be upon him) gave him one of his garments and intended to lead the funeral prayer over him. Sayyiduna Umar (may Allah be pleased with him) said: O Messenger of Allah, you know Abdullah (bin Ubayy) and his hypocrisy; will you pray over him when Allah Almighty has forbidden you to pray over him? He (peace and blessings be upon him) said: "Where has that been forbidden?" Sayyiduna Umar (may Allah be pleased with him) said: "Even if you ask forgiveness for them seventy times, Allah will never forgive them" [Surah al-Tawbah: 80]. The Messenger of Allah (peace and blessings be upon him) said: "Then I will ask forgiveness more than seventy times." Thereupon Allah, the Mighty and Majestic, revealed this verse: "And never pray over any of them who dies, nor stand at his grave" [Surah al-Tawbah: 84], and Allah Almighty also revealed: "It is the same for them whether you ask forgiveness for them or do not ask forgiveness for them; Allah will never forgive them" [Surah al-Munafiqun: 6].
Then a man came to the Messenger of Allah (peace and blessings be upon him) and sat for a very long time. The Prophet (peace and blessings be upon him) went out three times so that he would follow him (peace and blessings be upon him) out, but he did not get up. Then Sayyiduna Umar (may Allah be pleased with him) came in, saw the man, and perceived from the face of the Messenger of Allah (peace and blessings be upon him) his displeasure at the man's remaining seated, so he said: Perhaps you have caused the Prophet (peace and blessings be upon him) discomfort. The man understood and stood up. The Prophet (peace and blessings be upon him) said: "I got up three times hoping that you would follow me, but you did not do so." Sayyiduna Umar (may Allah be pleased with him) said: O Messenger of Allah, if only you would appoint a doorkeeper, for your wives are not like other women, and this screen is for the purity of their hearts. Thereupon Allah, the Mighty and Majestic, revealed this verse: "O you who believe, do not enter the houses of the Prophet unless permission is given to you" [Surah al-Ahzab: 53] to the end of the verse. Then the Messenger of Allah (peace and blessings be upon him) sent for Sayyiduna Umar (may Allah be pleased with him) and informed him of it.
And the Messenger of Allah (peace and blessings be upon him) consulted Sayyiduna Abu Bakr and Sayyiduna Umar (may Allah be pleased with them both) about the captives. Sayyiduna Abu Bakr (may Allah be pleased with him) said: O Messenger of Allah, spare the lives of your people, take ransom from them and seek help with it. Sayyiduna Umar bin al-Khattab (may Allah be pleased with him) said: Kill them. He (peace and blessings be upon him) said: "Had you both agreed on one view, I would not have gone against you." So the Messenger of Allah (peace and blessings be upon him) acted on the opinion of Sayyiduna Abu Bakr (may Allah be pleased with him), and Allah, the Mighty and Majestic, revealed this verse: "It is not fitting for a prophet to have captives until he has thoroughly subdued (the enemy) in the land; you desire the goods of this world, while Allah desires the Hereafter" [Surah al-Anfal: 67]. Then this verse was revealed: "And indeed We created man from an extract of clay" [Surah al-Mu'minun: 12] to the end of the verses, and Sayyiduna Umar (may Allah be pleased with him) said: "Tabarak Allahu ahsan al-khaliqin (Blessed is Allah, the best of creators)," and these very words were revealed in the verse: "So blessed is Allah, the best of creators" [Surah al-Mu'minun: 14].
Hadith Referenceالمعجم الكبير للطبراني / باب العين / 12192