Praise be to Allah.
It is not permissible to buy shares in riba-based banks. Anyone who has done such a thing must repent to Allah, may He be exalted, and take his capital, then get rid of the remaining money by spending it in the public interests of the Muslims or on charitable causes.
Because these shares are haraam, the basic principle is that it is not permissible for you to sell them to anyone. Rather the way to get rid of them is to return them to the bank. If that is not possible, it is permissible for you to sell them and take the capital that was invested in them, then to get rid of the rest in the ways referred to above.
The scholars of the Permanent Committee for Iftaa’ were asked: I had shares in a company, and this company went bankrupt 25 years ago. There were some trustees in charge of the company, who used the remaining funds to buy shares in the Bank of Riyadh 25 years ago, at the cost of 1000 riyals for a single share. Now the price of a single share is 30,000. I need this money; is it permissible for me to take the current price of the share? Please note that their purchase of shares in the Bank of Riyadh was done without our knowledge all this time.
They replied: Take the entire amount, principal and interest, then keep the principle because it belongs to you, and give the interest in charity, because it is riba. Allah will make you independent of means by His grace and will compensate you with something better than that, and He will help you to meet your needs. Whoever fears Allah - He will make for him a way out and will provide for him from where he does not expect, and whoever puts his trust in Allah, Allah will suffice him.
And Allah is the source of strength. May Allah send blessings and peace upon Prophet Muhammad and upon his family and companions. End quote.
‘Abd al-‘Azeez ibn ‘Abdillah ibn Baaz, ‘Abd ar-Razzaaq ‘Afeefi, ‘Abdullah ibn Ghadyaan, ‘Abdullah ibn Qa‘ood.
Fataawa al-Lajnah ad-Daa’imah (13/506).
They were also asked (13/508): What is the ruling on buying shares in companies and banks? Is it permissible for someone who has shares in a company or bank to sell his shares to a company that deals in buying and selling shares, when it is possible to sell them for more than the value for which he bought them? What is the ruling on the interest that the shareholder receives every year on the value of his shares?
They replied: buying shares in banks and companies that deal with riba is not permissible. If the shareholder wants to get rid of his riba-based shares, he may sell them at the current market value, then take his original capital only; the rest should be spent on charitable causes. It is not permissible for him to take any of the interest on his shares or their riba-based profits. But if the shares are in a company that does not deal with riba, then with any profits on the shares are permissible. End quote.
Do not regret the loss of this wealth, because it is haraam wealth in which there is nothing good for you, and there is the hope that Allah will compensate you with something better than it, as it was narrated in a sound report from the Prophet (blessings and peace of Allah be upon him) that whoever gives up something for the sake of Allah, Allah will compensate him with something better than it.
May Allah help us and you to do that which He loves and is pleased with.
And Allah knows best.