Then the Prophet ﷺ gave the order, and they were cast into a well. He went to them and called out, "So-and-so, son of so-and-so, so-and-so, son of so-and-so, have you found what Allah and His Messenger promised you to be true? For I have indeed found what Allah promised me to be true."I said, "Messenger of Allah, how can you speak to bodies that have no souls in them?"He replied, "You do not hear what I say better than they do, except that they are unable to give me any reply."
ثم أمر النبي ﷺ فطرحوا في بئر، فانطلق إليهم فقال: يا فلان بن فلان يا فلان بن فلان، هل وجدتم ما وعدكم الله ورسوله حقا؟ فإني قد وجدت ما وعدني الله حقا قلت: يا رسول الله! كيف تكلم أجسادا لا أرواح فيها؟ قال: ما أنتم بأسمع لما أقول منهم، غير أنهم لا يستطيعون أن يردوا علي شيئا.
Muslim narrated it in the Book of Paradise (2873) through several routes from Sulayman bin Mughira, from Thabit, from Anas bin Malik, from Umar bin Khattab, who mentioned it in the story of the death sites of the people of Badr.