Abu Ja‘far Muhammad ibn Ali ibn al-Husayn ibn Babawayh, may Allah سبحانه وتعالى have mercy on him, mentioned and said:
(Imam) Al-Sadiq عليه السلام, peace be upon him, was asked: “Why is Maghrib three rak‘ahs, and why are there four rak‘ahs after it which are never shortened, whether at home or while traveling?” Imam عليه السلام said: “Indeed, Allah سبحانه وتعالى, the Exalted, revealed to His Prophet, peace and blessings be upon him and his family, every prayer as two rak‘ahs. Then the Messenger of Allah سبحانه وتعالى, peace and blessings be upon him and his family, added two rak‘ahs to each prayer while in residence, and they were shortened during travel, except for Maghrib and the morning prayer. When He صلى الله عليه وعلى آله وسلم, peace be upon him and his family, prayed Maghrib, the news of the birth of (Sayyidah) Fatimah صلى الله عليه وعلى آله وسلم, peace be upon her, reached Him صلى الله عليه وعلى آله وسلم. Thus, He صلى الله عليه وعلى آله وسلم added one rak‘ah to it out of gratitude to Allah سبحانه وتعالى, Mighty and Majestic. Then when al-Hasan عليه السلام, peace be upon him, was born, He صلى الله عليه وعلى آله وسلم added two rak‘ahs out of gratitude to Allah سبحانه وتعالى, Mighty and Majestic. Then when al-Husayn عليه السلام, peace be upon him, was born, He صلى الله عليه وعلى آله وسلم added two more rak‘ahs out of gratitude to Allah سبحانه وتعالى, Mighty and Majestic. So He صلى الله عليه وعلى آله وسلم said: ‘To the male belongs a share equal to that of two females’, and He صلى الله عليه وعلى آله وسلم left it in that state, both during travel and at home.”