Rav Ovadia on Praying for the Deathly Ill
There are times that it is permissible to pray for someone who is terminally ill for his/her suffering to disappear the other way. See the Halachot of when and how to do so here in English or here in Hebrew.
Note the story in the last paragraph:
Let us now relate an incident that happened several years ago. There was a person who was unfortunately in a vegetative state for many years. His wife suffered tremendously, for she saw her life wasting away before her since her husband would not recover and she would live out her entire life without having children. When Maran Shlit”a heard about this, he arrived at the home of the ill man and proceeded to perform a “Tikun” (corrective ceremony) quoted by the works of the Mekubalim in the presence of ten men. Immediately following the Tikun, the ill man passed away in peace.