Borrowing money on the basis of riba is emphatically forbidden and is a major sin, because Allah, may He be glorified and exalted, says (interpretation of the meaning):
“O you who believe! Fear Allaah and give up what remains (due to you) from Ribaa (from now onward) if you are (really) believers.
279. And if you do not do it, then take a notice of war from Allaah and His Messenger but if you repent, you shall have your capital sums. Deal not unjustly (by asking more than your capital sums), and you shall not be dealt with unjustly (by receiving less than your capital sums)”
And Muslim (1598) narrated that Jaabir (may Allah be pleased with him) said: The Messenger of Allaah (peace and blessings of Allaah be upon him) cursed the one who consumes riba and the one who pays it, the one who writes it down and the two who witness it, and he said: they are all the same.
So it is not permissible to take out a riba-based loan or to mortgage the house in order to take out such a loan.
The one who takes out a riba-based loan is not obliged to pay the interest; rather he has to pay back the original amount of the loan only. If he is not able to do that, and he gave something to the lender as collateral, it is permissible to sell the collateral in two cases:
1.If the borrower gave permission to sell it, whether he gave permission at the time the contract was drawn up or at the time payment became due.
2.If the court rules that it is to be sold.
It says in Zaad al-Mustaqni‘: When the debt is due to be repaid and he refuses to pay, if the borrower gave permission to the lender to sell it, he may sell it and pay off the debt, otherwise the judge may force him to pay off the debt or sell the collateral. If he does not do that, the judge may sell it to pay off the debt. End quote.
The court may appoint someone to sell it, whether it appoints the lender or someone else.
It is stipulated that the one who sells it, whether it is the lender or someone else appointed by the judge, should sell it for the market price and not for less than that.
It says in Mughni al-Muhtaaj, 3/71:
The collateral should not be sold except for the current price in the local currency of something similar; if that condition is not met, then the sale is not valid. But if it is a little below the going price, which often happens when people bargain, that does not matter because they usually overlook that. End quote.
Based on that, if the item is sold because the borrower is unable to pay off the original loan, and that is done on the orders of the court and it is sold by public auction, there is nothing wrong with that and it does not matter if the seller did not give consent, because selling an item when its owner is reluctant is valid if he is forced to do so for a legitimate reason, and this is not regarded as buying something that was unlawfully confiscated or taken by force.
Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) said: The words ‘so it [the transaction] is not valid if he is forced to sell it without a legitimate reason’ – he commented on this by saying: If it is sold when the owner is reluctant for a legitimate reason, there is nothing wrong with that, because this is restoring the dues of others, i.e., if we force someone to sell something for a legitimate reason, this is restoring the dues of others, and is not wrongdoing or transgression.
For example: a person gave his house as collateral to someone for a debt that he owed to him. The time for repayment came and the lender asked for his money, but the borrower who owed the debt refused to pay. In this case, the borrower may be forced to sell his house, so that he can pay off what he owes to the lender.
Another example: A piece of land was owned by two people, and it was a small piece of land that could not be divided. One of the partners asked the other to sell, but the other partner refused. In this case the land may be sold despite the objections of the one who refused, because there is a legitimate reason, which is to ward off harm from his partner.
So the guideline is: If forcing someone to sell is for a legitimate reason, the sale is valid even if the seller does not give consent to it. Because in this case we are not committing a sin by wronging him or by any other means, so it is permissible. End quote from al-Sharh al-Mumti‘, 8/108
There is nothing wrong with buying a house from the second purchaser and adding it to the mosque.
And Allah knows best.