Praise be to Allah.
Stipulating that an additional amount be repaid when repaying a loan comes under the heading of riba (usury) concerning which there is no difference of scholarly opinion that it is prohibited.
It says in Fataawa al-Lajnah ad-Daa’imah (2/11/111):
Stipulating that an additional amount be repaid on a loan is blatant riba, because the Prophet (blessings and peace of Allah be upon him) said: “Every loan that brings a benefit is riba.” And the scholars are unanimously agreed on that. End quote.
There is no difference in the ruling regardless of whether the stipulated additional amount will go back to the lender or to someone else, because it is an additional amount stipulated in the loan contract, therefore it is riba in either case. Shaykh ‘Ulaysh al-Maaliki said in Fath al-‘Aliy al-Maalik fi’l-Fatwa ‘ala Madhhab al-Imam Maalik (1/363):
The fourth issue: with regard to conditions having to do with the loan, they fall into three categories: a category which renders the loan invalid; a category that does not render the loan invalid and must be fulfilled; and a category concerning which there is a difference of scholarly opinion.
The first category includes everything that brings a benefit to someone other than the borrower, whether it benefits the lender or someone other than the lender or the borrower. End quote.
If the borrower wants to benefit other students, it is permissible for him to return the loan with something extra, as a voluntary donation on his part, without that being stipulated in the contract, because returning a loan with something extra that was not previously stipulated is permissible, because it comes under the heading of paying off loans properly, and is not riba.
This has been discussed previously in fatwa 148458.
And Allah knows best.