All praise is due to Allah. May Allah's peace and blessings be upon our Prophet Muhammad, his family, and all his companions.
This is really an obscure issue. Describing an investment as impermissible because it involves some prohibited dealings is reckless. This is because a transaction or shares are not described as prohibited except if it consists of a principal activity which is prohibited, and the investment is based on a prohibited thing. However, if the principal activity is permissible whether it is a service, goods, property, and then interest-based loans or debentures are later involved in it, then in that case these loans may spoil the activity if their proportion is high. However, if their proportion is low and secondary, this does not affect the original ruling of the activity.
I call upon everyone to cleanse their transactions from all impurities, especially if a person is investing funds which people have entrusted them. Therefore, that person should strive to free himself and others from impurities and doubts. Therefore, he should purify his wealth in proportion to the doubtful issues that occur therein.
As for the person who invests while thinking that he is investing in a sound and clean venture, and then it later becomes clear that the venture is prohibited, the profits that he gained prior to that will be his, because the ruling regarding that is if a person enters into a transaction while thinking that it is permissible, then all the earnings that he gets therein will be permissible. The proof for that is Allah's statement: " Allah has pardoned what is past" [al-Maaidah: 95]. Allah did not take the people to task because of involvement of interest in the past, and he forgave them. However, if a person knows that what he is involved in is totally impermissible, then he should not be involved in such transactions.
However, if it becomes apparent that the transaction has some impurities, my view is that a person who wants to avoid doubts should avoid it based on the hadeeth of an-Nu'man ibn Basheer (may Allah be pleased with him) who narrated that the Prophet (peace be upon him) said, "Both legal and illegal things are evident but in between them there are doubtful (suspicious) things and most of the people have no knowledge about them. So whoever saves himself from these suspicious things saves his religion and his honor." The statement "his religion" is with regards to the servant and Allah. The statement "his honor" is with regards to what is between the person and other people. Therefore, a person has the right to avoid a sale, donation, or so on. If he wants to continue in these transactions then I cannot aver that this is impermissible. However, if the proportion of the prohibited things is small then it should be purified accordingly.
Shaykh Khalid al-Mosleh