Although not strictly illegal, you may be able to claim wrongful dismissal if you can prove you were still able to perform all tasks required for your job and therefore your medical problems did not affect your production.
Employers are allowed to "fire at will" except for discriminatory practices protected by government regulation. If you are missing too much work because of your health, your employer has the right to fire you. If you are disabled, you may be eligible for Social Security Disability.
In the UK section 15 of The Equality Act states an employer discriminates against a person when it treats that person less favourably, not because of the disability itself, but because of something arising "in consequence of that person's disability," such as the need to take a period of disability-related absence.
For this type of discrimination to occur, the employer must know, or reasonably be expected to know, that the disabled person has a disability. This type of discrimination will be easier for an employee to show since there will be no need to make a comparison with a person who does not have a disability. It will, however, be possible for an employer to defend a claim by showing that the treatment is justified as being a proportionate means of achieving a legitimate aim.
In America the ADA (Americans With Disabilities Act) does not say that if you have a disability, you cannot be fired. A disabled employee can be fired for any reason that a non-disabled employee can be fired for - they simply cannot be fired because they have a disability.
No it is not legal, since your employer is aware he should not have fired you, hence you are still fit for the job. But if he thinks, you are no longer strong he should not fire you. He has to on the contrary, things to you and should be giving reasonable amount of money each month. So his firing you is not right.
According to your story, what happened with you was completely wrong and you do not deserve to be treated this way. The way your employer treated you was completely wrong unethical. The employer only has the right to take such kind of an action if the employee is having some kind of a physical problem which is not enabling him to work productively. You also mentioned that he used to use derogatory comments on you which were totally immoral. You should have taken an immediate action there itself. But now what is done is done and you need to fight for your dignity. Being fired on such immoral grounds is wrong and you should immediately file a suit against the employer and the company. You have a very strong case and you should immediately consult a lawyer. The lawyer will help you with everything.
These kinds of cases are being seen everywhere in the world when the employer fires the employee when he captures AIDS or some other related disease. Many employees this way have won their dignity back by suing the employer.
I think that it was illegal for him/her to fire you if your job was not affected. It almost goes with that term "creating a bad work environment for you" if you've overhead comments or criticisms. I think you may have legal grounds to file a suit.