Imran bin Husain (may Allah be pleased with him) narrated that the companions of the Messenger of Allah ﷺ captured a man from Banu Aqil, so they tied him with ropes and threw him in Harrah (the black stony land of Madinah). The Messenger of Allah ﷺ passed by him and we were with him, or he said: The Messenger of Allah ﷺ came to him riding a donkey and there was a blanket under him. He called out to you ﷺ saying, "O Muhammad! O Muhammad!" So the Prophet ﷺ came to him and asked, "What is the matter?" He said, "For what crime have I been arrested? And for what fault has the she-camel (Adhba), which leads the pilgrims, been seized?" He ﷺ replied, "You have been arrested because of the actions of your allies, Thaqif." And Thaqif had captured two companions of the Prophet ﷺ. The Prophet ﷺ left him and went away. Then he called out again, "O Muhammad! O Muhammad!" The Messenger of Allah ﷺ felt compassion for him and returned to him and asked, "What is the matter?" He said, "I am a Muslim." The Prophet ﷺ said, "If you had said this when you were the master of your own affair (i.e., not captured), you would have been completely successful." Then the Prophet ﷺ left him and went away. He called out again, "O Muhammad! O Muhammad!" The Prophet ﷺ returned to him again and he said, "I am hungry, feed me." The narrator says, I think he also said, "And I am thirsty, give me water." The Prophet ﷺ said, "This is your need." Then the Messenger of Allah ﷺ released him in exchange for the two men whom the people of Thaqif had captured, and he also took back his she-camel.
Hadith Referenceمسند الإمام الشافعي / كتاب الأسر والفداء وضرب الجزية وأخذها / 1767
Hadith Takhrijاخرجه مسلم، النذر، باب لا وفاء لنذر في معصية الله ولا فيما لا يملك العبد (1641)۔