Praise be to Allaah.
Shaykh ‘Abd al-‘Azeez ibn Baaz (may Allaah have mercy on him) was asked:
What is the ruling on giving treatment before sickness occurs, such as vaccinations?
There is nothing wrong with giving treatment if there is the fear that the disease may occur because of the presence of an epidemic or other factors which may cause disease. There is nothing wrong with giving medicine to ward off the feared disease, because the Prophet (peace and blessings of Allaah be upon him) said, according to the saheeh hadeeth, “Whoever eats seven dates of Madeenah in the morning will not be harmed by witchcraft or poison.” This is a kind of warding off a problem before it happens. So if there is the fear of sickness and a person is vaccinated against an infection that is present in the land or elsewhere, there is nothing wrong with that, because it is a kind of protection. But it is not permissible to wear or hang up amulets etc against sickness, the jinn or the evil eye, because the Prophet (peace and blessings of Allaah be upon him) forbade that, and explained that this is a kind of minor shirk [associating others in worship with Allaah], so it must be avoided.
Fataawa al-Shaykh Ibn Baaz, 6/21
With regard to the harm suffered by those who are given some vaccinations, namely a short-lived fever or other side-efects, these drawbacks may be overlooked when compared with the great harm that is warded off, namely the diseases that may kill or cause great harm to a person’s health.
This is similar to the case of circumcising boys by cutting off a piece of skin and the intense pain that is caused to the infant; this is outweighed by the great benefits that are served by this action, serving the religious interest of purity (tahaarah) and numerous worldly benefits.
The general shar’i principle with regard to this matter is that the lesser of two evils may be done in order to ward off the greater evil, if it is necessary to do one of them. Al-Ashbaah wa’l-Nazaa’ir by al-Subki, 1/45.
But if it is medically proven that a specific vaccine causes harm to the body or that its harmful effects outweigh its effects of warding off disease, then it is not permissible to use it in that case, because the Prophet (peace and blessings of Allaah be upon him) said, “There should be neither harm nor reciprocating harm.”
And Allaah knows best.