The Talmud teaches that the mitzvos were given for our benefit and refinement, not for God's benefit — encapsulated in the phrase that the commandments were given only to purify human beings (לצרף בהם את הבריות).
אָמַר רַבִּי יוֹסֵי בְּרַבִּי חֲנִינָא: שָׁלֹשׁ אֲמָתוֹת הַלָּלוּ לָמָּה? — אָמְרָה חַנָּה לִפְנֵי הַקָּדוֹשׁ בָּרוּךְ הוּא: רִבּוֹנוֹ שֶׁל עוֹלָם, שְׁלֹשָׁה בִּדְקֵי מִיתָה בָּרָאתָ בָּאִשָּׁה, וְאָמְרִי לַהּ: שְׁלֹשָׁה דִּבְקֵי מִיתָה. וְאֵלּוּ הֵן: נִדָּה, וְחַלָּה וְהַדְלָקַת הַנֵּר. כְּלוּם עָבַרְתִּי עַל אַחַת מֵהֶן?! — ״וְחַנָּה הִיא מְדַבֶּרֶת עַל לִבָּהּ״. אָמַר רַבִּי אֶלְעָזָר מִשּׁוּם רַבִּי יוֹסֵי בֶּן זִמְרָא: עַל עִסְקֵי לִבָּהּ. אָמְרָה לְפָנָיו: רִבּוֹנוֹ שֶׁל עוֹלָם, כׇּל מַה שֶּׁבָּרָאתָ בָּאִשָּׁה, לֹא בָּרָאתָ דָּבָר אֶחָד לְבַטָּלָה: עֵינַיִם לִרְאוֹת, וְאׇזְנַיִם לִשְׁמוֹעַ, חוֹטֶם לְהָרִיחַ, פֶּה לְדַבֵּר, יָדַיִם לַעֲשׂוֹת בָּהֶם מְלָאכָה, רַגְלַיִם לְהַלֵּךְ בָּהֶן, דַּדִּים לְהָנִיק בָּהֶן. דַּדִּים הַלָּלוּ שֶׁנָּתַתָּ עַל לִבִּי לָמָּה? לֹא לְהָנִיק בָּהֶן?! תֵּן לִי בֵּן, וְאָנִיק בָּהֶן.
Rabbi Yosei, son of Rabbi Ḥanina, said: Why are these three maidservants [amatot] cited in the verse? They are cited to teach that Hannah said before the Holy One, Blessed be He: Master of the Universe, You have created three crucibles potentially leading to death in a woman, where she is particularly vulnerable. Alternatively, some say: Master of the Universe, You have created three accelerants of death in a woman. They are mitzvot that, as a rule, pertain to women: Observing the halakhot of a menstruating woman, separating ḥalla from dough, and lighting Shabbat candles. Have I ever violated one of them? Hannah attests to her status as God’s maidservant [ama]. The reference to these three mitzvot is drawn from the etymological similarity between amatekha, your maidservant, and mita, death. The Gemara continues to deal with Hannah’s prayer. It is said: “And Hannah spoke on her heart.” Several interpretations are offered to explain her use of the phrase “on her heart” instead of the common phrase to her heart (Maharsha). Rabbi Elazar said in the name of Rabbi Yosei ben Zimra: Hannah spoke to God concerning matters of her heart. She said before Him: Master of the Universe, of all the organs You created in a woman, You have not created one in vain. Every organ fulfills its purpose; eyes to see, ears to hear, a nose to smell, a mouth to speak, hands with which to perform labor, feet with which to walk, breasts with which to nurse. If so, these breasts that You placed upon my heart, to what purpose did You place them? Was it not in order to nurse with them? Grant me a son and I will nurse with them.