Praise be to Allah.
If the person who borrowed from you was in the habit of giving you gifts before the loan, such as if he was a friend or relative of yours etc, then there is nothing wrong with your accepting the gift in that case, because it had nothing to do with the loan.
But if this person was not in the habit of giving you gifts, it is not permissible for you to accept it, because it may be because of the loan, and if you accept it you may fall into riba (usury), because the basic principle regarding loans is that “Every loan which brings a benefit is riba,” and this loan will have brought you a benefit. See questions no. 30842 and 39505.
Also: he may be giving it to you to make you agree to delay asking for repayment, which is also a kind of riba.
This is indicated by the report narrated by Ibn Maajah (2432) from Yahya ibn Abi Ishaaq who said: I asked Anas ibn Maalik: What if man gives his brother a loan, then (the borrower) gives him a gift? The Messenger of Allaah (peace and blessings of Allaah be upon him) said: “If any one of you borrows something then he gives (the lender) a gift or gives him a ride on his riding-beast, he should not accept the gift or the ride, unless they used to treat each other in that manner beforehand.” Classed as hasan by Shaykh al-Islam Ibn Taymiyah in al-Fataawa al-Kubra, 6/159.
Ibn Sireen narrated that ‘Umar (may Allaah be pleased with him) lent Ubayy ibn Ka’b (may Allaah be pleased with him) ten thousand dirhams, and Ubayy ibn Ka’b gave him a gift of some fruit from his land, but he returned that to him and did not accept it. Ubayy came to him and said: “The people of Madeenah know that I grow some of the best fruit and I have no need of it, so why did you refuse my gift?” Then later on he sent him (some fruit) and he accepted it. Ibn al-Qayyim said: ‘Umar refused it because he thought that the gift was because of the loan. When he realized that it was not because of the loan, he accepted it. This is the decisive answer concerning the issue of accepting a gift from a debtor.
Al-Bukhaari narrated in his Saheeh (3814) that Abu Burdah said: I came to Madeenah and met ‘Abd-Allaah ibn Salaam (may Allaah be pleased with him). He said to me: “You are in a country where the practice of Riba (i.e. usury) is prevalent; so if somebody owes you something and he sends you a present of a load of chopped straw or a load of barleyor a load of fodder then do not take it, as it is Riba.”
This view was narrated from several of the Sahaabah. Ibn al-Qayyim said in I’laam al-Muwaqqi’een (3/136): It was narrated from more than one of them (i.e., the Sahaabah) – such as Ubayy ibn Ka’b, Ibn Mas’ood, ‘Abd-Allaah ibn Salaam, Ibn ‘Umar and Ibn ‘Abbaas – that they forbade the lender to accept a gift from the borrower, and they regarded accepting it as riba.
Al-Shawkaani said in Nayl al-Awtaar (6/257):
The point is that if gifts, loans etc are given for the sake of delaying payment of the loan, or as a bribe to the one who gave the loan, or so that the one who gave the loan will benefit as a result of his loan, that is haram, because it is a kind of riba or bribe. But if that is because the lender and borrower used to do that before this loan, then there is nothing wrong with it. If that is not done for any obvious purpose then it seems that the general prohibition should apply in this case.
Some of the scholars are of the view that it is permissible for the lender to accept a gift from the borrower, but it is better not to do so, to be on the safe side. Ibn al-Qayyim said in I’laam al-Muwaqqi’een (3/136): The Sunnah of the Messenger of Allaah (peace and blessings of Allaah be upon him) and the way of his companions is more deserving of being followed.
Is there any other solution apart from refusing the gift or falling into riba?
The answer is: Yes. If you insist on accepting the gift, you have two choices: you can respond in kind, giving something of equal or greater value, or you can regard it as part of the debt and waive the value of the gift from the amount owed.
Sa’eed ibn Mansoor narrated in his Sunan from ‘Abd-Allaah ibn ‘Umar that a man came to him and said: I lent money to a man whom I do not know and he gave me a valuable gift. He said: Give his gift back to him, or count it as part of the repayment.
Sa’eed ibn Mansoor also narrated that Saalim ibn Abi’l-Ja’d said: A man came to Ibn ‘Abbaas and said: I lent twenty dirhams to a man who sells fish and he gave me a fish which I estimated was worth thirteen dirhams. He said: Take seven dirhams from him.
See al-Fataawa al-Kubra by Ibn al-Qayyim, 6/159.
Shaykh Ibn ‘Uthaymeen said in al-Sharh al-Mumti’ (9/61):
If someone were to say: So long as this is haraam, why shouldn’t he just give it back in the first place?
We say: because he may feel too shy or embarrassed to return it, or he may hurt his companion deeply if he gives it back. So we say: Take it, and plan to repay him with a gift of equal or greater value, or to deduct its value from the loan. There is nothing wrong with this.
What we have stated above about it being haraam applies if the gift is given before the loan is paid off. If it is given after the loan is paid off, there is nothing wrong with accepting it.
Shaykh Ibn ‘Uthaymeen said in al-Sharh al-Mumti’ (9/59):
If he is given a gift shortly after the loan is paid off or a long time after that, it is permissible.
See al-Mughni, 6/437; al-Sharh al-Mumti’, 9/59-61.