The Prophet ﷺ said, "Whoever intercedes on behalf of his brother and is given a gift in return for that intercession, and he accepts it, has entered through a great door among the doors of usury."
عن النبي ﷺ قال: من شفع لأخيه بشفاعة، فأهدي له هدية عليها، فقبلها، فقد أتى بابا عظيما من أبواب الربا.
Abu Dawud (3541) narrated it from Ahmad bin Amr bin Sarh, who said, Ibn Wahb narrated to us, from Umar bin Malik, from Ubayd bin Abu Jafar, from Khalid bin Abu Imran, from Qasim, from Abu Umama, who said, and then he related the hadith. Its chain is hasan because of Khalid bin Abu Imran, for he is hasan al-hadith. His teacher Qasim is Ibn Abdul-Rahman Dimashqi, Abu Abdul-Rahman, who is disputed, though he too is hasan al-hadith. As for Ubaydullah bin Abu Jafar, he is trustworthy and one of the narrators found in Sahih Bukhari, so there is no basis for those who have criticized him.Imam Ahmad (22251) narrated it as well, through the route of Ibn Lahia, who said, Ubaydullah bin Abu Jafar narrated to us, with his chain, in similar fashion. Ibn Lahia has well-known criticism against him, but he has been corroborated. The hadith has other chains besides these, but the one I have mentioned is the soundest of them.There is no contradiction between this hadith and the hadith of Ibn Umar, "Whoever does you a favor, repay him for it." That is a sahih hadith, narrated by Imam Ahmad (5365) and Abu Dawud (5109), and graded sahih by Ibn Hibban (3408) and Hakim (1/412). See its sourcing in the book on zakat.The hadith under discussion indicates a warning against accepting a gift from someone for whom one has interceded on behalf of a brother, and who was then given a gift and accepted it. The hadith of Ibn Umar indicates repaying someone who has done a favor other than intercession, and there are many categories of favors, so there is no conflict between the two hadiths.As for a gift that someone offers in order to ward off injustice from himself, or to obtain a right that is owed to him, such a gift is forbidden for the one who takes it, though it is permissible for the one who offers it to give it, in order to obtain his right. For more, see Majmu Fatawa Ibn Taymiya (31/285–287).As for what has been related from Anas bin Malik as a saying of the Prophet, "If one of you lends someone a loan, and the borrower then gives him a gift, or lets him ride his mount, he should not ride it and should not accept it, unless something of that sort had already occurred between them before the loan," this is daif.Ibn Majah (2432) narrated it from Hisham bin Ammar, who said, Ismail bin Ayyash narrated to us, who said, Utba bin Humayd Dabbi narrated to me, from Yahya bin Abu Ishaq Hinai, who said, I asked Anas bin Malik, "A man among us lends his brother money, and then the brother gives him a gift, what about that?" He said, the Messenger of Allah ﷺ and then he related the hadith.This hadith has several defects. Among them is the weakness of Ismail bin Ayyash. Among them also is the weakness of Utba bin Humayd Dabbi. Ahmad said, "He was from the people of Basra, and he wrote down a great deal, but he is daif, not strong, and people have not found his hadith to be free of confusion."Among them also is the obscurity of Yahya bin Abu Ishaq Hinai, who is also said to be Yazid bin Abu Ishaq, and also said to be Yazid bin Abu Yahya, and also said to be Yahya bin Yazid Hinai.Among them also is that raising it to the level of a saying of the Prophet is a mistake, and the correct position is that it is a stopped narration, meaning one attributed only to Anas himself.Bukhari said in Tarikh al-Kabir (8/310), in the biography of Yahya bin Yazid Abu Yazid Hinai, "Adam told this to us, Shuba narrated to us, that he heard Yahya bin Yazid, I said to Anas, regarding a man who has a debt owed to him, He said, He should not ride behind him on his mount. And it was said, Abu Muawiya narrated, from Abu Qilaba, from Anas, from the Prophet, and this is a mistake." End of quote.Bayhaqi said (5/350), "Shuba and Muhammad bin Dinar narrated it, and both of them made it a stopped narration."Among the defects also is inconsistency in the chain of transmission. And Allah, the Exalted, knows best what is correct.