The Yalkut Shimoni (Eikev Remez 871) brings a wondrous story about this:
“There was a woman who aged a lot, and she came to Rabi Yosi ben Chalafta and said to him: Rebbi, I have aged too much and now my life is just one of atrophy and withering, I do not taste food or drink, and I ask depart from this world. He said to her: Which mitzvah do you do every day? She said to him: I am accustomed that even if I have something I like, I set it aside and rise early to go to shul each day. He said to her: Do not go to shul for three days in a row. She did as he said and on the third day she fell ill and died.”
Rav Eliyahu Hakohein Ha’Itamari pointed out that even though l’halachah Rabi Yosi ben Chalafta was not allowed to give the woman advice that would hasten her death, he did it anyway so that those in his generation would clearly see how rising to go to shul gives a person arichus yamim, and through that they should strengthen their observance of this mitzvah. Because as Chazal teach (Brachos 54a), when necessary, it is permitted to do something forbidden for the sake of kavod Shamayim, as it says (Tehillim 119:126): “Eis la’asos l’Hashem heferu Torasecha” (Midrash Talpiyos, Beis Haknesses).