"And Hannah, she was speaking upon her heart" (1 Samuel 1:13). Why were women joined together with minors and slaves regarding the commandments? Because they have only one heart, as it is said, "And Hannah, she was speaking upon her heart." "And I find more bitter than death the woman whose heart is snares and nets" (Ecclesiastes 7:26). "And her husband arose and went after her to speak upon her heart" (compare Judges 19:3). And likewise the minor: "Folly is bound up in the heart of a youth" (Proverbs 22:15). And likewise the slave: his heart is set only upon his master. The wicked are in the possession of their heart: "The base man said in his heart" (Psalms 14:1); "And Esau said in his heart" (Genesis 27:41); "And Jeroboam said in his heart" (1 Kings 12:26); "And Haman said in his heart" (Esther 6:6). But the righteous — their heart is in their own possession, as it is said, "And Hannah, she was speaking upon her heart"; "And David said unto his heart" (1 Samuel 27:1); "And Daniel set upon his heart" (Daniel 1:8). They resemble their Creator: "And the LORD said unto His heart" (Genesis 8:21).
Why Hannah and the Righteous Rule Their Own Hearts
Yalkut Shimoni on Nach 78:3
וחנה היא מדברת על לבה. למה נשתתפו (ה) הנשים עם הקטנים והעבדים לענין המצות, לפי שאין להם אלא לב אחד, שנאמר וחנה היא מדברת על לבה. ומוצא אני מר ממות את האשה אשר היא מצודים וחרמים לבה. ויקם אישה וילך אחריה לדבר על לבה. וכן הקטן אולת קשורה בלב נער, וכן העבד לבו אל אדונו בלבד. הרשעים הם ברשות לבם אמר נבל בלבו, ויאמר עשו בלבו, ויאמר ירבעם בלבו, ויאמר המן בלבו. אבל הצדיקים לבם ברשותם שנאמר וחנה היא מדברת על לבה, ויאמר דוד אל לבו, וישם דניאל אל לבו, דומים לבוראם ויאמר ה' אל לבו: