All perfect praise be to Allah the Lord of the Worlds. May His peace and blessings be upon Prophet Mohammad and upon all his family and companions.
A loan is the act of giving money to someone for his or her benefit, with the condition that the same amount is returned later, seeking the pleasure of Allah Almighty. It is permissible for the borrower and recommended for the lender.
In a loan, it is an obligation upon the borrower to repay it in the same form it was borrowed. If money was borrowed, it must be repaid in money; if gold was borrowed, it must be repaid in gold, by weight. This is because ownership in a loan is established by possession, and the borrower remains liable for the debt in the same form he received it.
Al-Khateeb Al-Shirbini (may Allah have mercy on him) said: "In a loan, the repayment should be in kind for what is an equivalent (Muthli), as it is closer to fulfilling the right, even if the currency is no longer in use for transactions." [Mughni Al-Muhtaj/Vol.3/P.33]. This is what was affirmed by the International Fiqh Academy in its fifth session, where it stated in its resolution: "The criterion for repaying debts is by the same kind (Muthli), not by value, because debts are repaid with their equivalents."
In conclusion, if the lender sells the gold and gives the borrower its price in money, the borrower must repay the exact amount of money they borrowed. However, if the lender gave the borrower the gold and the borrower then sold it, the borrower is obligated to repay the equivalent of the gold in weight. There is no objection to repaying the equivalent in money, provided both parties agree on this at the time of repayment, using the price of gold on the day of repayment, and with the condition that the exchange (payment) is completed in the same session. And Allah The Almighty Knows Best.