My question is whether or not a commandment can be broken in cases that could prevent an illness (e.g if it was certain that eating pig could prevent a certain type of cancer, consuming freshly crushed herbs on shabbos to prevent a certain disease etc.)?
TL;DR: According to some authorities, future danger to life allows for current intervention that violates biblical halakha if necessary. However, that may only apply in cases where the future danger is likely. In cases where the danger is unlikely, even those poskim might be stringent. Some poskim are lenient in cases where there is a current indication (such as a genetic mutation) that makes it likely that in the future a person will become dangerously ill. This is in between a case of current pikuah nefesh, and future pikuah nefesh.
R. Eliezer Berkovitz notes in Berur Halakha B'din Nittuhei Metim (printed in in Sinai (69 pp. 45-66)) that Sanhedrin (26a) states in explanation of the statement of R. Shimon in Sanhedrin (3:3) that when the tax collectors became abundant, people would work the fields during the shemittah year. Tosafot there (s.v. misherabu) explains in the second answer that if they didn't have have the grain they would be unable to pay their taxes and would be killed. Therefore, it was considered pikuah nefesh and they could violate biblical commands.
It appears that (according to this) in a case where one knows that in the future lives will be endangered, he may take steps now, even in violation of biblical law, to prevent it.
Similarly, the Hazon Ish ruled (YD Hilkhot Avelut 208:7) regarding performing autopsies (otherwise forbidden as mutilation of the dead) to gain medical knowledge to save lives, that it would be permissible even if the theoretical patients whose lives would be saved are not here right now, as long as it is is a common disease, such that it is known that someone in the future will be affected by it.
For a related discussion see Teshuvot V'hanhagot (3:105).
However, while it is true that according to some views biblical law can be violated now to prevent future loss of life, those cases are apparently cases in which it is very likely that life will be endangered, and in the case of Tosafot, where it is very likely that violating the prohibition will solve the problem. However, although normally even if someone only might be in danger (e.g. a person is buried under rubble and he may or may not already be dead) we allow violation of biblical commandments, and similarly, we violate biblical commandments even where the treatment is guaranteed to be effective, perhaps in cases of future danger to life, the degree of certainty that there will be a danger and and that the treatment would need to be effective, are higher.
Notably, in discussing removal of ovaries and Fallopian tubes from women undergoing hysterectomies, assuming that there is a 5% chance of cancer developing there, R. Moshe Feinstein in Igrot Moshe (HM 2:73) does not mention pikuah nefesh / danger in that case, as a reason to be lenient, except as an afterthought. His primary reasoning only invokes details relevant to that particular case:
ליכא שום חשיבות ושם השחתה על מה שנשארו השחלות וצנורות הרחם והוי זה כצער וחבלה בשאר אבריה שלטובתה אין לאסור
He does mention the possible future danger as more of a reason to be lenient:
וגם הא שעלול להעשות סרטן אף שהוא רק בסך חמשה אחוזים יש להחשיב סכנה להאשה להתיר זה דהוא חשש גדול
There is also a case between imminent pikuah nefesh, and future pikuah nefesh. That is a case in which there is currently a factor that that makes a future danger likely. For example, if an Ashkenazi woman has the BRCA mutation, she can be perfectly healthy, but have a 60% or 40% chance of developing breast cancer, and a 53% or 62% chance of developing ovarian cancer, depending on which mutation she has (ibid). Accordingly, Rabbis Avraham Steinberg, Zalman Nehemiah Goldberg, and Asher Weiss are quoted (ibid) as permitting prophylactic oophorectomy (removal of the ovaries) although according to some there is a biblical prohibition of castration, that according to some applies to females, on the grounds of pikuah nefesh. Although she is not currently sick, her genetic predisposition that she had from birth, is considered sufficient.
I understand your question as whether taking preventive medicine allows to break commandments, i.e., does preventing future health issues has a status similar to saving lives (pikuach nefesh) which as we know allows to break most commandments.
I also understand that
- there is an element of probability in there (you write "could prevent an illness"), i.e., the preventive medicine reduces the health risk but does not eliminate it completely
- the health risk might lead to premature death, or not
- we are speaking of a healthy person to start with (as the rules for non-seriously ill or seriously ill patients are different)
I will aim to show that there is no opening to breaking commandment for a healthy person who might possibly prevent future health issues this way based on two arguments
- Halachic medical leniencies do not apply to normal healthy people
- The specific examples (eating forbidden foods, crushing herbs on Shabbat) do have leniencies but, again, they don't apply to healthy people
First one should know the halacha defines a number of categories for sick people: choleh she'yesh bo sakana (seriously ill patient), chole she'eyn bo sakana (non-seriously ill patient), mitztaer (someone suffering from a certain degree of discomfort). Each of these will have different leniencies apply to him, e.g.,
- one can turn on a light to attend to a seriously ill patient (Nishmat Avraham vol. 1, p. 129) or generally transgress the Shabbat for him (but only as required, ibid. p. 185)
- the non-seriously ill patient who has already suffered a heart attack can jog on Shabbat if he does so daily to prevent another heart attack (Nishmat Avraham vol. 1, p. 140)
- one is permitted to ask a non-Jew to perform a rabbinic violation for a mitztaer (see bottom of here)
However these leniencies do not apply to normal healthy people, as such for instance
- a healthy person who jogs regularly to prevent heart attacks should not do so on Shabbat (Nishmat Avraham vol. 1, p. 140)
- a patient (i.e., not a healthy person) can only take medication on Shabbat if omitting it would cause him harm, or if he would be cured only by taking the medicine a given number of days incl. Shabbat (Nishmat Avraham vol. 1, p. 177 but Shmirat Shabat K'hilchata is lenient)
As was mentioned in comments, each commandment has certain leniencies but they are relevant to sick people only, e.g.,
- a seriously ill person can ingest pills containing non-kosher ingredients, even non-seriously ill patients can often eat them as ingesting pills is not defined as eating (see e.g., here and here)
- one can cut and crush aromatic herbs in order to wave them over the head of a patient (SA OC 322:5)
As such I do not think there is any opening to breaking commandment for a healthy person who might possibly prevent future health issues this way.
The more I think of the question, the more I think the halacha depends on how certain the probabilities are, e.g.,
- if eating pork saves a life immediately - no question it is permitted
- if it will for sure save a life in the future - it will very likely be permitted
- if it might possibly save a life in the future - it will very likely not be permitted
Remember to CYLOR before applying anything you read here to real life.
PS. Nishmat Avraham is a classic sefer on medical halacha, see here