We praise Allah for having guided you to repent, for the best thing that a person can do in this world is to turn sincerely to Allah. When Allah wills good for a person, He opens the door to humility for him, and makes him see his faults, ignorance, wrongdoing and transgression of His limits, and softens his heart so that he may repent, pray for forgiveness and regret his sins and shortcomings.
Your work in a mixed environment and manufacturing and producing things that may be used in haram ways was one of the haram things which are forbidden by Islamic sharee’ah (law) so as to protect religious commitment and to protect Muslim societies, in adherence to the limits set by Allah, so as to venerate His laws and in acknowledgement of His might, may He be glorified and exalted.
Ibn al-Qayyim said in al-Wabil al-Sayyib:
As for the signs of being serious about keeping away from forbidden things, they are: keeping away from things that could lead to them, and avoiding all means of drawing close to them, such as the one who flees from places in which there are images that lead to fitnah (temptation), for fear of being tempted by them, and giving up things with which there is nothing wrong for fear of things that are wrong, and avoiding excessive indulgence in permissible things for fear of falling into that which is makrooh (disliked), and avoiding people who commit sin openly or regard it as good and promote it and take it lightly and do not care about what they do of sin. Mixing with such people is likely to incur the wrath and anger of Allah, so no one mixes with them except the one whose heart is lacking in respect for Allah and His sacred limits. End quote.
Sewing immodest women’s clothes – for those who will wear them for sinful purposes and use them to cause fitnah (temptation) – is a haram action, because it is helping with evil. What the Muslim must do is respect the sacred limits of Allah and not accept to be a means of Allah being disobeyed or agree to be one of the helpers and troops of the shaytan (devil).
Ibn Taymiyah said in Sharh al-‘Umdah:
For any garment that it is thought will be likely to be used for sinful purposes, it is not permissible to sell it or sew it for the one who will use it for sinful purposes. The same applies to everything that is basically permissible, if it is known that it will be used for sinful purposes. End quote.
He also said, in Majmoo’ al-Fatawa:
If he helps a man to disobey Allah then he is sinning, because he has helped in sin and transgression. Hence the Prophet (peace and blessings of Allah be upon him) cursed alcohol, the one who squeezes (the grapes, etc), the one for whom it is squeezed, the one who carries it, the one to whom it is carried, the one who sells it, the one who buys it, the one who pours it, the one who drinks it and the one who consumes its price.
Most of these people, such as the one who squeezes (the grapes, etc), the one who carries it and the one who pours it are helping in drinking it. Hence it is forbidden to sell weapons to one who will use them in unlawful fighting, such as fighting the Muslims or fighting in fitnah (civil war). End quote.
Ibn Hazm said in al-Muhalla:
It is not permissible to sell anything to someone who will certainly use it to disobey Allah and the transaction is null and void. For exampe, such as selling anything that may be squeezed or pressed to one who will certainly use it to make alcohol, or selling a slave to one who will certainly mistreat his slaves, or selling weapons or horses to one who will certainly use them for aggression against the Muslims, or selling silk to one (a man) who will certainly wear it, and so on with regard to all things, because Allah says (interpretation of the meaning):
“Help you one another in Al‑Birr and At‑Taqwa (virtue, righteousness and piety); but do not help one another in sin and transgression. And fear Allah. Verily, Allah is Severe in punishment.”
The transactions that we have mentioned are obviously helping in sin and transgression, and annulling them is helping in righteousness and piety. If no such thing is certain then the transaction is valid, because it is not helping in sin, and if the purchaser disobeys Allah after that, then the sin is on him. End quote.
It says in al-Mawsoo’ah al-Fiqhiyyah: It is not permissible to practise a profession that leads to haram or that may help in committing haram, such as tattooing, because it involves changing the creation of Allah, or recording riba (interest), because this involves helping to consume people’s wealth unlawfully, and so on. End quote.
One of the conditions of repenting from haram wealth is getting rid of it, by spending it in the interests of the Muslims and on various charitable causes.
Ibn Taymiyah said in Majmoo’ al-Fatawa: The one who accepts payment for haram things, such as payment for those who carry alcohol, or payment for the one who makes a cross, or the fees of a prostitute and so on, should give it in charity and repent from that haram action, and giving that payment in charity will be an expiation for what he has done. It is not permissible to make use of these payments because they are evil wages. End quote.
It says in al-Furoo’ by Ibn Muflih: In the case of haram wealth, what must be done is repentance and getting rid of it immediately. End quote.
What you must do is work out how much you earned from sewing clothes for immodest women, then give it to the poor and needy in the hope that it will expiate your previous sins. As for the property that you have acquired from working in that factory – including the sewing machine – you do not have to get rid of it, because the reason why it is haram is not directly connected to the original work, rather it is because of the mixing that accompanied it, which has nothing to do with the original work, unless the factory’s work was haram in the first place, such as manufacturing alcohol, cigarettes or haram machines, in which case you would have to get rid of the wages that you took from it.
If you are in difficulty and you cannot get rid of all the money that you acquired from sewing haram clothes, then there is no sin on you if you keep what you need.
Shaykh al-Islam Ibn Taymiyah said in Majmoo’ al-Fatawa:
If this prostitute and this wine-maker have repented and they are poor, it is permissible to give them as much of this money as they need. But if he is able to engage in business or do a handicraft such as weaving or spinning, he should be given enough to serve as capital (to set himself up in business). End quote.
And Allah knows best.