Praise be to Allah.
The individual should avoid the pain and suffering that results from some contagious and fatal diseases. The proof for that is the words of the Prophet (blessings and peace of Allah be upon him): “No sick (camel) should be put with healthy (camels).” The one who owns camels that are sick with mange and the like must not bring them to land or water to which the one who owns healthy camels brings his camels, lest the sickness be transmitted from the sick camels to the healthy camels, and thus spread further.
It was narrated that the Messenger of Allah (blessings and peace of Allah be upon him) said: “Flee from the leper as you would flee from a lion.”
We believe that diseases cannot become contagious by themselves, because the Prophet (blessings and peace of Allah be upon him) said: “There is no ‘adwa (contagion) and no tiyarah (superstitious belief in bird omens).” That is, these diseases are not contagious in and of themselves; rather Allah causes them to be transmissible and He has created in them that which causes the disease to pass from one person to another. Thus mixing became a cause of that, and people should avoid the causes by means of which the disease is transmitted, in compliance with the instructions and guidelines mentioned in the hadiths.
Undoubtedly everything happens by the will and decree of Allah. Allah, may He be glorified and exalted, criticized those who believed in bird omens when He said (interpretation of the meaning): “But when good came to them, they said, ‘This is ours [by right].’ And if a bad [condition] struck them, they saw an evil omen in Moses and those with him” [al-A‘raaf 7:131]. In other words, they were saying: This is bad luck that was brought by Moosa and those who are with him, and it has only befallen us because of their evil. But Allah criticized them by saying: “Unquestionably, their fortune is with Allah , but most of them do not know” [al-A‘raaf 7:131].
The evidence clearly indicates that if sicknesses are transmitted as a result of mixing with those affected by them, that transmission only happens by Allah’s leave. A person could mix with others without becoming infected, by the protection of Allah.
For more information, please see the answer to question no. 137801.
And Allah knows best.