Praise be to Allah.
Purchase of apartments through the Housing and Development Bank is done in two ways, according to what we were able to find out:
In the first scenario, it is purchased directly from the building societies by instalments, where the bank plays no role in that, but instalments are paid into the account of the seller through the bank. This is permissible and there is no problem with it.
In the second scenario, this bank or another bank is involved as financer; the bank pays the price of the apartment to the building society on behalf of the purchaser, then takes it back from him by instalments, with something more than it paid. This is a riba-based loan and is haraam.
If the bank is a third party in this transaction, then you must find out what its role is, because the bank may buy the property from the first party, then sell it to the second party on the basis of profit-sharing (mudaarabah), provided that the bank takes possession of the apartment in a real sense, and the apartment becomes the property of the bank which becomes able to dispose of it, and provided that no penalty is stipulated in the event of delay in repayment, as has been explained previously in the answer to question no. 162000.
Or the bank may have no role, apart from being the means of delivering the money from the purchaser to the owner. Both of these are permissible.
As for the bank being involved as the financer, without buying the apartment for itself, then selling it to the customer, this is a riba-based loan, because the bank is paying on behalf of the customer, then taking it back from him with something extra (interest) that is stipulated in the contract.
If the apartment was purchased in a permissible manner, then there is nothing wrong with a second purchaser taking the place of the first purchaser in dealing with the bank and paying instalments.
But if the apartment was purchased in an unlawful (haraam) manner, and there are riba-based instalments that remain to be paid, then it is permissible to buy it from the owner with a price paid on the spot or by instalments, but provided that it does not mean that the second purchaser is taking the place of the first purchaser in dealing with the riba-based bank, because of the infractions that result from that, such as opening an account in that bank, or committing to pay a penalty (interest) in the event of any delay in paying instalments. Such commitments are haraam, even if the person is determined not to delay payments.
If the owner of the apartment takes responsibility for paying instalments himself, and is the one who is dealing with the bank, then there is nothing wrong with buying the apartment from him, even if it remains registered in his name, but you must document your rights properly.
If you buy it from him by instalments, there is nothing wrong with it if the instalments you pay are equal to the instalments that he pays to the bank.
See also the answer to question no. 165262.
And Allah knows best.