Quaeritur: If God's knowledge and will are immutable, unchanging, then why pray for things, if God has already decided what He will do, and knows infallibly what will occur? In other words, if He has already eternally decided that x will happen and infallibly knows it will happen, what's the point of praying for y to happen if it won't happen, and what's the point of praying for x to happen--if it will happen anyway? So what's the point of praying at all if our prayers are incapable of changing God's knowledge or will?
Respondeo: Correct. God's intellect and will are immutable, and our prayers cannot change them. Yet prayer is still valuable and may actually be the cause (a secondary cause, not the primary cause) of our receiving what we pray for. God's infallible decree that something will happen may be conditional upon your praying for it. In other words, God may infallibly decree that He will grant x to you if and only if you pray for x, and know that you will pray for x, and hence that you will get x (or that you won't pray for it and hence that you won't get it).
The reason why God would want us to pray, and especially why He would make our prayer a condition for granting what we pray for, is that prayer—as Aquinas tells us—is for our own benefit (not God's). Through it we become conscious that we need to receive benefits from Him; it is an act of religious worship (latria), whereby we become conscious of our dependence on and submission to Him.
Consider the following texts of St. Thomas:
ST II-II.83.2: Whether it is becoming to pray? I answer that among the ancients there was a threefold error concerning prayer. Some held that human affairs are not ruled by Divine providence; whence it would follow that it is useless to pray and to worship God at all: of these it is written (Malachi 3:14): "You have said: He laboreth in vain that serveth God." Another opinion held that all things, even in human affairs, happen of necessity, whether by reason of the unchangeableness of Divine providence, or through the compelling influence of the stars, or on account of the connection of causes: and this opinion also excluded the utility of prayer. There was a third opinion of those who held that human affairs are indeed ruled by Divine providence, and that they do not happen of necessity; yet they deemed the disposition of Divine providence to be changeable, and that it is changed by prayers and other things pertaining to the worship of God. All these opinions were disproved (in ST I.19.7-8, I.22.2-4; I.115.6; I.116).
Wherefore it behooves us so to account for the utility of prayer as neither to impose necessity on human affairs subject to Divine providence, nor to imply changeableness on the part of the Divine disposition. In order to throw light on this question we must consider that Divine providence disposes not only what effects shall take place, but also from what causes and in what order these effects shall proceed. Now among other causes human acts are the causes of certain effects. Wherefore it must be that men do certain actions, not that thereby they may change the Divine disposition, but that by those actions they may achieve certain effects according to the order of the Divine disposition: and the same is to be said of natural causes. And so is it with regard to prayer. For we pray not that we may change the Divine disposition, but that we may impetrate that which God has disposed to be fulfilled by our prayers; in other words "that by asking, men may deserve to receive what Almighty God from eternity has disposed to give," as Gregory says (Dial. i, 8)
To the first it must be said that we need to pray to God, not in order to make known to Him our needs or desires but that we ourselves may be reminded of the necessity of having recourse to God's help in these matters.
SCG I.119: That the immutability of divine providence does not suppress the value of prayer.
[1] We should also keep in mind the fact that, just as the immutability of providence does not impose necessity on things that are foreseen, so also it does not suppress the value of prayer. For prayer is not established for the purpose of changing the eternal disposition of providence, since this is impossible, but so that a person may obtain from God the object which he desires.
[2] Indeed, it is appropriate for God to consent to the holy desires of a rational creature, not in the sense that our desires may move the immutable God, but that He, in His goodness, takes steps to accomplish these desired effects in a fitting way. For, since all things naturally desire the good, as we proved above, and since it pertains to the supereminence of divine goodness to assign being, and well-being, to all in accord with a definite order, the result is that, in accord with His goodness, He fulfills the holy desires which are brought to completion by means of prayer.