How Does Tefillah Work?
וַיִּגַּ֥שׁ אַבְרָהָ֖ם וַיֹּאמַ֑ר הַאַ֣ף תִּסְפֶּ֔ה צַדִּ֖יק עִם־רָשָֽׁע׃
Abraham came forward and said, “Will You sweep away the innocent along with the guilty?
אֶעְבְּרָה־נָּ֗א וְאֶרְאֶה֙ אֶת־הָאָ֣רֶץ הַטּוֹבָ֔ה אֲשֶׁ֖ר בְּעֵ֣בֶר הַיַּרְדֵּ֑ן הָהָ֥ר הַטּ֛וֹב הַזֶּ֖ה וְהַלְּבָנֹֽן׃
Let me, I pray, cross over and see the good land on the other side of the Jordan, that good hill country, and the Lebanon.”

ונראה כי ה' ניסה אותם להדריכם לשאת עיניהם ולהתפלל לפני ה' כי זה עיקר גדול באמונה ובהשלמת הנפש.

It appears that G'd's purpose in subjecting the people to this test was to train them to raise their eyes heavenwards, to pray and to implore G'd in times of need because this is an important principle in matters of faith and attempts to perfect one's personality.

(א) ה' אלקים צבאות שמעה תפלתי האזינה אלקי יעקב סלה (תהלים פד). פסוק זה אמרו דוד ע"ה והיה מתחנן להקב"ה שישמע תפלתו לפי שעם התפלה יתקרב אדם לבוראו

... This Pasuk states that Dovid was pleading to Hashem to listen to his prayer as with tefillah man draw close to Hashem

ודע שמעשי העבודות האלו כולם כקריאת ה'תורה' והתפילה ועשות שאר ה'מצוות' אין תכלית כונתם - רק להתלמד להתעסק במצוות האלוה ית' ולהפנות מעסקי העולם וכאילו אתה התעסקת בו ית' ובטלת מכל דבר זולתו. אבל אם תתפלל בהנעת שפתיך ופניך אל הכותל - ואתה חושב במקחך וממכרך ותקרא ה'תורה' בלשונך - ולבך בבנין ביתך מבלי בחינה במה שתקראהו; וכן כל אשר תעשה 'מצוה' - תעשנה באבריך - כמי שיחפור חפירה בקרקע או יחטוב עצים מן היער מבלי בחינת ענין המעשה ההוא לא מי שציוה לעשותו ולא מה תכלית כונתו - לא תחשוב שהגעת לתכלית. אבל תהיה אז קרוב ממי שנאמר בהם "קרוב אתה בפיהם ורחוק מכליותיהם":
We must bear in mind that all such religious acts as reading the Law, praying, and the performance of other precepts, serve exclusively as the means of causing us to occupy and fill our mind with the precepts of God, and free it from worldly business; for we are thus, as it were, in communication with God, and undisturbed by any other thing. If we, however, pray with the motion of our lips, and our face toward the wall, but at the same time think of our business; if we read the Law with our tongue, whilst our heart is occupied with the building of our house, and we do not think of what we are reading; if we perform the commandments only with our limbs, we are like those who are engaged in digging in the ground, or hewing wood in the forest, without reflecting on the nature of those acts, or by whom they are commanded, or what is their object. We must not imagine that [in this way] we attain the highest perfection; on the contrary, we are then like those in reference to whom Scripture says, "Thou art near in their mouth, and far from their reins" (Jer. 12:2).
שְׁמַע קוֹלֵֽנוּ יְהֹוָה אֱלֹהֵֽינוּ חוּס וְרַחֵם עָלֵֽינוּ וְקַבֵּל בְּרַחֲמִים וּבְרָצוֹן אֶת־תְּפִלָּתֵֽנוּ כִּי אֵל שׁוֹמֵֽעַ תְּפִלּוֹת וְתַחֲנוּנִים אָֽתָּה וּמִלְּפָנֶֽיךָ מַלְכֵּֽנוּ רֵיקָם אַל־תְּשִׁיבֵֽנוּ
Hear our voice, Adonoy, our God; spare us and have compassion on us, and accept our prayers compassionately and willingly, for You are Almighty Who hears prayers and supplications; and do not turn us away empty-handed from Your Presence, our King, for You hear the prayers of Your people, Israel, with compassion. Blessed are You, Adonoy, Who hears prayers.

Why do we ask Hashem for all of these things and then at the very end ask him not to return us empty handed? Isn't that insulting?

וְהִ֖יא מָ֣רַת נָ֑פֶשׁ וַתִּתְפַּלֵּ֥ל עַל־יְהֹוָ֖ה וּבָכֹ֥ה תִבְכֶּֽה׃

In her wretchedness, she prayed to the LORD, weeping all the while.

וַתִּדֹּ֨ר נֶ֜דֶר וַתֹּאמַ֗ר יְהֹוָ֨ה צְבָא֜וֹת אִם־רָאֹ֥ה תִרְאֶ֣ה ׀ בׇּעֳנִ֣י אֲמָתֶ֗ךָ וּזְכַרְתַּ֙נִי֙ וְלֹֽא־תִשְׁכַּ֣ח אֶת־אֲמָתֶ֔ךָ וְנָתַתָּ֥ה לַאֲמָתְךָ֖ זֶ֣רַע אֲנָשִׁ֑ים וּנְתַתִּ֤יו לַֽיהֹוָה֙ כׇּל־יְמֵ֣י חַיָּ֔יו וּמוֹרָ֖ה לֹא־יַעֲלֶ֥ה עַל־רֹאשֽׁוֹ׃

And she made this vow: “O LORD of Hosts, if You will look upon the suffering of Your maidservant and will remember me and not forget Your maidservant, and if You will grant Your maidservant a male child, I will dedicate him to the LORD for all the days of his life; and no razor shall ever touch his head.”

(יג) וְהָיָ֗ה אִם־שָׁמֹ֤עַ תִּשְׁמְעוּ֙ אֶל־מִצְוֺתַ֔י אֲשֶׁ֧ר אָנֹכִ֛י מְצַוֶּ֥ה אֶתְכֶ֖ם הַיּ֑וֹם לְאַהֲבָ֞ה אֶת־ה' אֱלֹֽהֵיכֶם֙ וּלְעׇבְד֔וֹ בְּכׇל־לְבַבְכֶ֖ם וּבְכׇל־נַפְשְׁכֶֽם׃
(13) If, then, you obey the commandments that I enjoin upon you this day, loving the LORD your God and serving Him with all your heart and soul,

וּמְנָא לַן דְּבִתְפִלָּה דְּתַנְיָא לְאַהֲבָה אֶת ה׳ אֱלֹקֵיכֶם וּלְעׇבְדוֹ בְּכׇל לְבַבְכֶם אֵיזוֹ הִיא עֲבוֹדָה שֶׁהִיא בַּלֵּב הֱוֵי אוֹמֵר זוֹ תְּפִלָּה

The Gemara asks: And from where do we derive that rain must be mentioned specifically in the Amida prayer? The Gemara answers: As it was taught in a baraita with regard to the verse: “To love the Lord your God and to serve Him with all your heart” (Deuteronomy 11:13). Which is the service of God that is performed in the heart? You must say that this is referring to prayer. .

אִיתְּמַר, רַבִּי יוֹסֵי בְּרַבִּי חֲנִינָא אָמַר: תְּפִלּוֹת אָבוֹת תִּקְּנוּם. רַבִּי יְהוֹשֻׁעַ בֶּן לֵוִי אָמַר: תְּפִלּוֹת כְּנֶגֶד תְּמִידִין תִּקְּנוּם.

It was stated: Rabbi Yosei, son of Rabbi Ḥanina, said: The practice of praying three times daily is ancient, albeit not in its present form; prayers were instituted by the Patriarchs. However, Rabbi Yehoshua ben Levi said that the prayers were instituted based on the daily offerings sacrificed in the Holy Temple, and the prayers parallel the offerings, in terms of both time and characteristics.

רְצֵה ה אֱלֹקֵֽינוּ בְּעַמְּ֒ךָ יִשְׂרָאֵל וּבִתְפִלָּתָם וְהָשֵׁב אֶת הָעֲבוֹדָה לִדְבִיר בֵּיתֶֽךָ וְאִשֵּׁי יִשְׂרָאֵל וּתְפִלָּתָם בְּאַהֲבָה תְקַבֵּל בְּרָצוֹן וּתְהִי לְרָצוֹן תָּמִיד עֲבוֹדַת יִשְׂרָאֵל עַמֶּֽךָ:

Be pleased, Adonoy, our God, with Your people, Israel, and their prayer; and restore the service to the Holy of Holies in Your abode, and the fire-offerings of Israel; and accept their prayer, lovingly and willingly. And may You always find pleasure with the service of Your people, Israel.

א"ר יצחק מפני מה היו אבותינו עקורים מפני שהקב"ה מתאוה לתפלתן של צדיקים

Rabbi Yitzḥak said: For what reason were our forefathers initially infertile? Because the Holy One, Blessed be He, desires the prayers of the righteous, and He therefore wanted them to pray for children.

התפלה היא במקום הקרבן ולכן צריך ליזהר שתהא דוגמת הקרבן בכוונה ולא יערב בה מחשבה אחרת כמו מחשבה שפוסלת בקדשים...

Prayer is in place of sacrifices (korbanot), and therefore one must be careful that it resemble the sacrifices with respect to intention, and not let other thoughts mix in, similar to unrelated thoughts which would nullify sacrifices...

וַהֲבִיאוֹתִ֞ים אֶל־הַ֣ר קׇדְשִׁ֗י וְשִׂמַּחְתִּים֙ בְּבֵ֣ית תְּפִלָּתִ֔י עוֹלֹתֵיהֶ֧ם וְזִבְחֵיהֶ֛ם לְרָצ֖וֹן עַֽל־מִזְבְּחִ֑י כִּ֣י בֵיתִ֔י בֵּית־תְּפִלָּ֥ה יִקָּרֵ֖א לְכׇל־הָעַמִּֽים׃
I will bring them to My sacred mount And let them rejoice in My house of prayer. Their burnt offerings and sacrifices Shall be welcome on My altar; For My House shall be called A house of prayer for all peoples.”
מה שהביא האנשים לפקפק בתפלה קרוב למה שהביא אותם לסלק ידיעת השם. וזה שהם אומרים שלא ימלט הדבר מחלוקה אם שנגזר מהשם טוב מה על איש מה או לא נגזר. ואם נגזר אין צריך תפלה, ואם לא נגזר איך תועיל התפלה לשנות רצון השם לגזור עליו טוב אחר שלא נגזר, שלא ישתנה השם מן הרצון אל לא רצון ולא מלא רצון אל רצון, ובעבור זה יאמרו שלא יועיל כשרון המעשה אל שיגיע לאדם מהשם בעבורו טוב מה, וכן יאמרו שלא תועיל התפלה להשיג טוב מה או להנצל מרע שנגזר עליו.

The reason which leads men to doubt the efficacy of prayer is the same as that which leads them to deny God’s knowledge. Their argument is as follows: Either God has determined that a given person shall receive a given benefit, or He has not so determined. If He has determined, there is no need of prayer; and if He has not determined, how can prayer avail to change God’s will that He should now determine to benefit the person, when He had not so determined before? For God does not change from a state of willing to a state of not willing, or vice versa. For this reason they say that right conduct is of no avail for receiving a good from God. And similarly they say that prayer does not avail to enable one to receive a benefit, or to be saved from an evil which has been decreed against him.

Rav Samson Raphael Hirsch, Horeb Part IV

Hitpallel, from which “Tefillah” is derived, originally meant to deliver an opinion about oneself, to judge oneself or an inner attempt at so doing such as the hitpael (reflexive) form of the Hebrew verb frequently denotes … Thus it denotes to step out of active life in order to attempt to gain a true judgment about oneself … about one’s relationship to God and the world, and the world to oneself …
In English we call Tefillah “prayer,” but this word only incompletely expresses the concept “to pray,” i.e., to ask for something is only a minor section of Tefillah.