This verse, "It is not for a prophet to act unfaithfully" [Al Imran 3:161], was revealed concerning a red velvet cloak that went missing on the day of Badr. Some people said, "Perhaps the Messenger of Allah ﷺ took it." So Allah revealed, "It is not for a prophet to act unfaithfully" to the end of the verse.
حدثنا قتيبة حدثنا عبد الواحد بن زياد عن خصيف حدثنا مقسم قال
نزلت هذه الآية {ما كان لنبي أن يغل} في قطيفة حمراء افتقدت يوم بدر فقال بعض الناس لعل رسول الله ﷺ أخذها فأنزل الله {ما كان لنبي أن يغل} إلى آخر الآية
[Its chain of transmission is daif. Abu Dawud narrated it in Huruf wal-Qiraat, chapter 1, hadith 3971, from Qutayba, with the same wording. The hadith has corroborating narrations in Wahidi's Asbab Nuzul, p. 107, and elsewhere. His saying "some people" means some of the hypocrites, as found in Wahidi's narration.