Imran bin Husayn reported,

Thakeef were allies of the tribe of Banu Aqeel. Thakeef captured two of the companions of the Messenger of Allah ﷺ, and the companions of the Messenger of Allah ﷺ captured a man from Banu Aqeel, taking with him the camel known as al-Adba.The Messenger of Allah ﷺ came upon him while he was bound in ropes, and the man called out, "Muhammad!" So he came to him and asked, "What is your situation?"The man said, "Why have you seized me, and why have you seized the camel that leads the pilgrims?"He replied, magnifying the matter, "I have seized you for the offense of your allies, Thakeef." Then he turned away from him.The man called out to him, "Muhammad! Muhammad!" The Messenger of Allah ﷺ was merciful and tender-hearted, so he returned to him and asked, "What is your situation?"The man said, "I am a Muslim."He replied, "Had you said this while you still had control over your own affair, you would have attained complete success." Then he turned away.The man called out again, "Muhammad! Muhammad!" He came to him and asked, "What is your situation?"The man said, "I am hungry, so feed me, and thirsty, so give me drink."He said, "This is your need." He was then ransomed in exchange for the two men. The hadith continues.

Azami 8007

Sahih

عن عمران بن حصين قال

كانت ثقيف حلفاء لبني عقيل، فأسرت ثقيف رجلين من أصحاب رسول الله ﷺ، وأسر أصحاب رسول الله ﷺ رجلا من بني عقيل، وأصأبوا معه العضباء، فأتى عليه رسول الله ﷺ وهو في الوثاق، قال: يا محمد فأتاه، فقال: ما شأنك؟ فقال: بم أخذتني؟ وبم أخذت سابقة الحاج؟ فقال: إعظاما لذلك، أخذتك بجريرة حلفائك ثقيف، ثم انصرف عنه، فناداه، فقال: يا محمد! يا محمد! وكان رسول الله ﷺ رحيما رقيقا فرجع إليه، فقال: ما شأنك؟ قال: إني مسلم. قال: لو قلتها، وأنت تملك أمرك، أفلحت كل الفلاح، ثم انصرف، فناداه فقال: يا محمد! يا محمد! فأتاه، فقال: ما شأنك؟ قال: إني جائع فأطعمني، وظمآن فاسقني، قال: هذه حاجتك، ففدي بالرجلين الحديث.

الأعظمي 8007صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Jihad
Chapter
Captives
Section
Ransoming Muslim captives with captives of the disbelievers
Numbering
Jami al-Kamil 8007 (2nd edition)
Azami 8007