The juxtaposition of the eternal nature of God, causality, and free will (since the eternal nature of God knowing what we will do before we do it implicates the question of free will) does indeed appear to present a theological quandary. In the area of prayers of petition and intercession, we run smack dab into the mystery of eternity and the interaction between eternity and the temporality in which we humans exist.
(a) On the one hand, being eternal, existing outside of and beyond linear time, God knows what will happen "before" it happens because, for Him, it has already happened. Moreover, being perfect, God does not make mistakes. And to "change one's mind" is to say, to some extent, that one was wrong before.
(b) On the other hand, Jesus clearly and expressly said, "ask and you shall receive" and "to pray always without becoming weary." (Mt. 7:7-8, Lk 18:1-7) And the prayer He commended to us, the "Our Father," contains many requests that God do this or that. There are multiple occasions too in the Old Testament where the Lord says that He is acting because He has heard the cries and prayers of His people. Moreover, we have the authority of Christ's holy Church, as guided by the Holy Spirit, which has taught from the earliest days that we should offer our prayers to God, including prayers of petition and intercession. (See CCC 2629-36) All of this does suggest that prayer has an effect on God, that He does do things in response to prayer that He might not have done if the prayer were not made.
So, these are complex questions, with seemingly contradictory answers. But, at the risk of confusing the issue further, and leaving aside the question of the effect of prayer on the person who prays, rather than on the person prayed for, here are three possible affirmative responses to these questions, and a couple of other points.
(1) (a) Prayer is not at all an academic exercise, but the question of whether prayer affects the actions of the eternal God does appear to be an academic question. God may do X only because we have prayed for Him to do X. However, being eternal, God already knows what happens before it happens. So, He knew not only what He was going to do, He already knew that we would pray for X before we asked for it. Conversely, if we did not pray for X, then God might not do X, but He knows that too before we fail to pray it. Either way, God already knowing what we are going to do before we do it doesn't mean that our prayers do not have an effect on what He might or might not do.
Prayer does have a real effect on God, even if it might appear, because of the mystery of eternity, that it does not.
That is, it might appear that our prayer does not have any real effect on what God is going to do in the sense that, being timeless, God already knows what He is going to do (from the human temporal perspective) and, indeed, has already done (from God’s out-of-time perspective). It might appear that prayer does not lead to God to do something, like save someone's life, if He was not going to already do it.
However, God not only knows what He is going to do before you pray for it, He also knows that you are going to make that prayer (or not). So when God chooses to act or not, He does so with the foreknowledge of your prayer or lack thereof. Being eternal and transcendent of time, so that everything that has ever happened and ever will happen in the human timeline is in God’s present, all of time being a singularity, the fact that He already knows and has already done it does not mean that what we have prayed for did not play a factor in whether it was done or not.
But let us set aside this mystery of eternity interacting with temporality, which mostly results in tying ourselves up in knots and, therefore confuses the issue.
(b) Instead, let us consider that it is clear that there are conditions precedent to some of God’s actions. You must do something, namely ask and/or accept, before He will do those actions. A prime example of this is the gift of grace. The gift of grace from God is not an action. It is a transaction. God does not unilaterally confer grace upon someone. That would be an imposition contrary to love. Rather, for grace to be conferred, (1) you must ask God for it and, once offered, (2) you must accept the gift. If you don’t ask and you don’t accept, you will not get it (that said, Jesus has already indicated that He stands ready to give it if we ask, so our asking, like any prayer, is really in response to His initiative).
It is not a case of God merely doing what He would have done anyway. Without your doing that condition precedent of asking or accepting, He would not have done it, even if He does know what the ultimate outcome is before it happens. God already knew that Mary would say “yes,” but that does not mean that her “yes” was not required, and was not freely given, before the Holy Spirit would come upon her.
The same might hold true for prayers of petition and intercession, as in the case of a person who is sick and suffering. The prior request for, and assent to, the grace of healing might be necessary, inasmuch as God does not impose Himself upon us against our will.
That said, whether God has in fact intervened in a given situation and altered what would have happened if He had not intervened is ultimately a matter of faith. It cannot be submitted to the scientific method. God cannot be put under the microscope. Either one believes that a healing was miraculous or he doesn’t. “All I know is that I was blind, and now I see.”
(2) Although God, and God alone, provides us salvation (in Christ), and although He is all-powerful, dependent upon none, He has chosen to need the assistance of humanity to accomplish the work of salvation. God has chosen not to do it all by Himself -- He wants our help. He wants us to participate in saving others by, among other things, praying for them, which has the transcendent effect of joining all the faithful together as one in communion with God.
Indeed, in the Sacrament of Confirmation, where Jesus asks us to join in the mission of the Church to be a witness for Him, we see that God has very much chosen to need the help and participation of humanity in saving others. God doesn't need our help, but He wants our help. He has chosen to depend upon us, including in the work of salvation. He has chosen to make this a group effort. Or, if you will, a family effort. The Almighty does not need our help, but He asks for it anyway. And if we do not provide that help, it isn't going to be done.
We see this in the very fact that He depended upon Mary for His very life, and depended upon her and Joseph to raise Jesus. The Jesus who saves by the Cross and Resurrection is always the Baby Jesus as well. The Baby Jesus who requires us to help Him.
If Mary didn't help God; if Mary didn't say "yes" and carry Jesus in her womb, and raise Him and teach Him and feed Him and clothe Him and shelter Him, the salvation of the world would have never come. God chose to need her. God chooses to need us.
Prayer for other people helps Him. Not because He needs our help, but because He wants our help. He wants that help, He wants us to love one another and care about the welfare of one another. Jesus wants us to pray for others -- the key part of "ask and you shall receive" is not the "receive" part, but the "ask" part. In the parables about the woman who keeps bothering the judge until he rules in her favor (Lk 18:1-7) and the man who pesters his reluctant friend in the middle of the night to give him some bread (Lk 11:5-8), Jesus tells us to be persistent in prayer. If we do not do things like pray, that help for others might not get done. That God already knows what we will do and what He will do does not detract from that. We need to help Him help them. We need to pray.
(3) Prayer also has a very real effect because God made us as social beings, He made us to exist, not in isolation, not in individualistic solitude, but in communion -- in communion not only with Him, but if each of us is one with Him, we are necessarily one with each other.
Even if God does not intervene to physically heal the person, our prayers are made use of. He does, in fact, do something that He would not have done had the prayers not been made. Implicit in prayer is love, inasmuch as prayer is communication with God, i.e. communion with Him, an exchange of love with Him. In His compassion, God is already with the sick and suffering. Such that when we pray for them in loving communion with God, that love is further communicated through Him to the sick person.
If we pray for the sick, if we give our love for that person to God, then He will convey that love of ours -- and the implicit power of healing in love -- to the sick person. However, if we do not pray for the sick, then God cannot convey such love to him or her since it has not been given to Him.
(4) Notwithstanding the widespread assertion that God listens to and answers every prayer (even if He sometimes says "no"), actually, on occasion, God purposely does not answer our prayers. In the case of one making a good faith prayer, He will listen, but He might not respond, at least not right away. We have only to look at not a few of the great saints who have experienced the "dark night of the soul" to understand this. Sometimes, God will withdraw. You may call out, "God? Are you there?" And receive nothing but silence in return. It does not mean that God has abandoned you. Sometimes, He will withdraw so that you might go looking for Him.
(5) One other point about prayer needs to be noted. God also sometimes will not even listen, sometimes He pays no attention to what we ask of Him. God is under no obligation to listen to or answer a "prayer" that borders on being blasphemous by being improper and inappropriate. Consider what happened when Herod effectively prayed that Jesus perform tricks for him --
"When Herod saw Jesus, he was greatly pleased, because for a long time he had been wanting to see Him. From what he had heard about Him, he hoped to see Him perform some miracle. He plied Him with many questions, but Jesus gave him no answer." -- Luke 23:8-9
(6) Finally, and most importantly, we need to remember that God is Love. God loves us. That's what He does. And He wants only what is good for us. Always, and in all things. And He does not abandon us. In that same lesson where Jesus says, "ask and you shall receive," He also says,
"Which one of you would hand his son a stone when he asks for a loaf of bread, or a snake when he asks for a fish? If you then, who are wicked, know how to give good gifts to your children, how much more will your heavenly Father give good things to those who ask him." (Mt. 7:7-11)God loves us. And when we say, "Thy will be done," as we should in all prayer, we should know that His will is always to love us in truth. Thus, even if it were the case that our prayers to Him had no effect on His actions, even if He were to do whatever it is that He is going to do regardless, He nevertheless wants what is good for us and He does what is good for us. He will not abandon us, He will not leave us alone in misery.
In His mercy (from the Latin miserere, meaning "to alleviate misery"), and His compassion (from the Latin "com," meaning "with," and passio, meaning "to suffer"), God suffers with us, as we most graphically see with Jesus taking on humanity and suffering on the Cross. And by the transformative power of His love, our misery is turned into hope, and then ultimately into joy in eternal life, where "He will wipe every tear from their eyes, and there shall be no more death or mourning, wailing or pain." (Rev. 21:4) God loves us, so even if He were to ignore our faithful prayers (which He does not), still we should not lose hope -- He Himself provides the hope. And such faithful prayer would not be in vain or otherwise pointless, loving communion with God in prayer is never in vain.
See also, Effects of prayer, Catholic Encyclopedia
C.S. Lewis, "The Efficacy of Prayer" (1959), reprinted in The World's Last Night
St. Augustine, Sermon 30 (LXXX. Ben.) (Augustine here asks "What is the use of prayer at all, if our Father knows already what things we have need of? . . . Why weary ourselves in asking, and seeking, and knocking, to instruct Him who knows already?" His conclusion is that we should indeed ask, we should pray, but his explanation is rather hard to follow.)
St. Alphonsus Ligouri, Necessity and Power of Prayer (Alphonsus says that, not only is God moved by prayer, but that without prayer, we cannot obtain the help (grace) necessary for salvation. "Hence it is that the generality of theologians, following St. Basil, St. Chrysostom, Clement of Alexandria, St. Augustine, and other Fathers, teach that prayer is necessary to adults, not only because of the obligation of the precept (as they say), but because it is necessary as a means of salvation. That is to say, in the ordinary course of Providence, it is impossible that a Christian should be saved without recommending himself to God, and asking for the graces necessary to salvation.")