"And it was, as she prayed long before the LORD" (I Samuel 1:12). Rabbi Chiyya in the name of Rabbi Yochanan, and Rabbi Shimon ben Chalafta in the name of Rabbi Meir: from here we learn that whoever prays at length is answered. The view of Rabbi Levi seems to contradict this, for it is written, "In all toil there is profit, but the talk of the lips leads only to want" (Proverbs 14:23). Rabbi Abba son of Rav Pappi and Rabbi Yehoshua of Sikhnin in the name of Rabbi Levi said: because Hannah prayed at length, she shortened the days of Samuel, as it is said, "and he shall dwell there forever" (I Samuel 1:22) — "forever" means the lifespan of the Levites, as it is written, "and from the age of fifty years he shall return from the service of the army" (Numbers 8:25). But those are fifty-two years! Rabbi Yosi bar Avin said: the two years are the years during which she nursed him.
How Hannah Praying at Length Shortened Samuel's Years
Yalkut Shimoni on Nach 78:12
והיה כי הרבתה להתפלל ר' חייא בשם ר' יוחנן ור' שמעון בן חלפתא בשם ר' מאיר מכאן כשכל המרבה בתפלה נענה. מיחלפא שיטתיה דר' לוי דכתיב בכל עצב יהיה מותר ודבר שפתים אך למחסור. ר' אבא בריה דרב פפי ור' יהושע דסכנין בשם ר' לוי חנה על ידי שרבתה בתפללה קצרה ימיו של שמואל שנאמר וישב שם עד עולם עד עולמו של לוים, דכתיב ומבן חמשים שנה ישוב מצבא העבודה. והא אינון חמשין ותרתין א"ר יוסי בר אבין שתים שגמלתו: