I’m a little confused about prayer. Hashem is only good. He only does good to us, and gives us things for our ultimate benefit. If someone has a medical problem why would he pray for it to go away? If that person has complete emunah and bitachon in Hashem that He only does what’s good for him and with complete love, then why would he ask for it to go away, more than that, how could he say to Him, “I know 100% that You only do good for me from absolute love and I thank You for what you’ve given me… but please take it away”. And if you want to say that Hashem just wants that person to ask Him to take it away, and then He will, if that person was smart he wouldn’t ask because he knows that yisurim remove sins, which in turn brings him closer to Hashem. So it would seem he’s better off not asking in the long run since he’ll be closer to God in the end.
Let me offer you two possible answers.
I once heard a very nice answer to this with a moshul, from R’ Zev Leff shlit”a. A patient comes to the doctor because he has poor circulation in his feet. If the problem isn’t that bad, he will prescribe some pills to dilate the arteries and veins and he will be fine. If the problem is worse, and the pills won’t do the job, although painful, he will suggest physical therapy to force the blood through the veins. If however the problem is terribly serious and the therapy doesn’t manage to get the blood through the veins, and the foot is getting gangrene, then he no choice but to amputate the leg.
If the patient is at the middle stage and the doctor prescribes pills for it, which won’t work, he is hurting his patient. On the other hand if he is going to amputate the leg instead of doing therapy, he belongs in jail.
It is the same with us. Unfortunately we do aveiros and stray from H-shem, and need for H-shem to correct us. However the medicine for the ailment depends on how severe the problem is. When we daven and make ourselves closer to H-shem through sincere tefilloh, we draw ourselves closer to Him. Therefore in a way we are telling H-shem, “H-shem you are right, I needed the ailment because of the level that I was on at that point. But maybe now I have reached a different level. I have cleared my arteries, and now maybe I will only need the pills, or maybe I am totally better now and I won’t even need that”.
Therefore it is true that H-shem knows what really is best for us, but we are changing now, and maybe what is good for us, now has changed.
Another answer may be, based on a Midrash (Rabba Beshlach 21-5, Tanchuma Shoftim 13) regarding the difficult situation that the Jews were in right before the sea was split for them. The Midrash asks, “Why did H-shem do this to them?” R’ Yehoshua ben Levi answer with a mosul. A king was traveling and he heard a lost princess crying, “save me from the thieves”. The king heard and saved her, (and cared for her, and provided her with all her needs). Later on the king wanted to marry her, but she wasn’t even willing to talk to the king. What did the king do? He sent thieves to her, and she started to scream again to the king. Then the king told her, this is what I wanted.”
On first glance it sounds like the king is selfish and being manipulative. But in truth that is not the case. Yes, the king wants a relationship with the princess, but the princess doesn’t realize that she needs the king for everything that she needs. Without this relationship with the king, she would have been robbed of everything, and they might have kidnapped her and she would be a maid. Thanks to the king she now has a life, and he is providing her with all her needs, and what the king essentially wants is to make her a queen. So in essence the king is helping her, and in a way forcing her to do what is best for herself.
It is the same with us. H-shem provide us with life, a body, family, sustenance, and everything we need in order to live. All he wants from us is that we should have a relationship with Him, do His mitzvos, and get close to Him, so we can be fortunate. We on the other hand get side tracked and stray from this relationship, and hurt ourselves. So H-shem, who knows what is best for us, sends us problems, specifically so that we should daven, and reconnect with Him. Perhaps that is why we had the problem in the first place, and the remedy for it is indeed the tefillah.