And to his virgin sister who is close to him, that is not married, for her he may become ritually unclean. (VaYikra 21:3)
1. The Torah source for the commandment to mourn the death of relatives
A kohen is generally prohibited from becoming ritually unclean. This prohibition restricts a kohen from contact with a dead body. There are exceptions to this restriction. A kohen is personally responsible for the burial of and to mourn a close relative. This obligation takes precedence over the restriction against spiritual impurity. The above passage explains that one of the relatives for whom an exception is made for the kohen’s unwed daughter.
One of the positive commands of the Torah is to mourn close relatives. No passage in the Torah expressly states this mitzvah. Maimonides, in his Sefer HaMitzvot, explains that the command is derived from the obligation of the kohen to become spiritually unclean in order to bury and mourn a close relative. And he cites our pasuk as the source of the positive commandment. He explains that the mitzvah of mourning is expressed in reference to the kohen in order to stress the importance of the command. A kohen is generally prohibited from becoming spiritually unclean. Yet, in order to honor the deceased this restriction is abrogated. Certainly, a Jew who is not restricted in becoming ritually unclean must properly care for and mourn the departed! ,
Do not cry over the departed and do not shake your head over him… (Sefer Yermiyahu 22:9)
2. Mourning should not exceed Torah standards
The Talmud explains that it is prohibited for a person to engage in excessive mourning. The Torah has established standards for mourning. It is appropriate to cry within the first three days of the burial. For the first seven days it is fitting to eulogize the departed. Some elements of mourning are observed for thirty days. A person who loses a parent engages in some elements of mourning for twelve months. However, each element of the mourning process should be limited to the time allotted to it by the Torah.
The Talmud’s discussion continues with an account of a woman who lost one of her sons. She could not be consoled. Rav Huna cautioned her that her response was excessive and her behavior might be punished by further catastrophe. She refused to heed his warning and was indeed punished with the loss of her surviving sons. Again, she refused to be consoled and Rav Huna warned her that she was risking further punishment. She was not deterred by Rav Huna. She was again punished with the loss of her own life. The Talmud closes the discussion by explaining that one should not show more compassion for the departed than is demonstrated by Hashem, Himself. The Talmud supports its position with the above passage in which it interprets as a criticism of extensive mourning and bereavement. 
3. Maimonides’ discussion of excessive mourning
Maimonides quotes the Talmud’s restriction against excessive mourning. However, in explaining the prohibition, he seems to depart somewhat from the message communicated by the Talmud. Maimonides comments that one who abandons the Torah’s standards for mourning and adopts more contemporary practices – thereby mourning in excess of the Torah’s requirement – is a fool.  In short, the Talmud seems to identify excessive mourning with criticism of Hashem’s standards. Maimonides adopts the position that these standards are wise and only a fool abandons them.
Both the Talmud’s comments and those of Maimonides require further consideration. The Talmud accuses the excessive mourner of criticizing Hashem. Precisely, how is this criticism reflected in the refusal to be consoled? Maimonides seems to be offering a different or an additional explanation for the restriction. Why is Maimonides offering an alternative to the Talmud’s explanation?
And Moshe said to Aharon, and Elazar and Etamar his sons: Do not grow your hair long and do not rend your garments and do not die. And He will be angered against the entire congregation. Your bothers – the entire House of Yisrael will mourn the burning that was caused by Hashem. (Sefer VaYikra 10:6)
4. Two aspects of mourning
In order to answer these questions the above passage must be considered. This passage relates to the tragic deaths of Nadav and Avihu described earlier in Sefer VaYikra. The construction of the Mishcan was followed by a period of inauguration. The first seven days of this period Moshe served as the Kohen Gadol. Aharon assumed his duties as High Priest on the eighth day. On that first day of Aharon’s service, his sons Nadav and Avihu died. Moshe instructed Aharon, that despite this tragedy, the service in the Mishcan should not be interrupted. Aharon and his sons should continue to perform their functions. They should not engage in the practices of mourning. Moshe cites two of these practices – not trimming one’s hair and rending one’s garment. Moshe then adds that all of Israel will mourn the deaths of Nadav and Avihu.
Why did Moshe add this last comment? Rabbaynu Yosef Bechor Shur offers a simple explanation. The death of Nadav and Avihu resulted in two imperatives. First, their family was obligated to mourn their loss. Moshe explained that in this instance that imperative would not apply and that Aharon and his sons must continue to perform the service in the Mishcan. Second, Nadav and Avihu’s deaths should be acknowledged. No decent person should pass from this world without notice. If Aharon and his sons were not permitted to mourn the passing of Nadav and Avihu, who would mourn in their place? Moshe responded that in the place of Aharon and his sons all of Israel would assume the role of mourners.
This passage communicates that there are two aspects to mourning. First mourning is an expression of personal loss. The mourner grieves the loss of his or her loved one and experiences the sorrow intrinsic in bidding farewell to the departed. Second, the mourning process acknowledges the departed and honors his or her memory. Moshe told Aharon and his sons that they would not be permitted to grieve. However, he assured them that the second aspect of mourning – honoring the departed – would be fulfilled through the mourning of the entire nation for this terrible loss.
5. The Torah establishes the standards for acknowledging the departed
With the identification of these two aspects of mourning, the questions developed above can be addressed. The Talmud treats excessive mourning as a criticism of Hashem. The mourner is communicating through his actions that Hashem’s compassion is inadequate. How is Hashem’s compassion expressed in the standards for mourning? Through establishing these standards the Torah and Sages assure that every decent person will be suitably honored at the time of his or her passing. No person’s death will be treated as meaningless or insignificant. However, the laws of mourning do not merely assure that every person’s death will receive acknowledgment. These laws also create a standard for appropriate acknowledgment. Exceeding this standard implies that the tribute required by Hashem is inadequate and something more is required. This is not appropriate.
6. Even personal grief must have bounds
However, the Talmud’s account of the woman who lost her sons does not seem to conform to this message. This woman was not mourning as a tribute to her lost son. She was feeling the heartrending anguish of a parent burying her offspring. She refused to be consoled because she could not reconcile herself to her loss. Despite the terrible tragedy of her loss, Rav Huna rebuked her – “Enough!” What was this poor woman’s sin?
Life and death are part of a natural cycle. All living things experience stages beginning with birth, progressing through growth into maturity, and then decline and death. Is death of a loved one ever timely? Does a son or daughter ever welcome the death of even an aged beloved parent? If one’s death evokes deep and painful grief, it is because the departed brought to those who grieve intense happiness and joy. To not grieve is to not have loved.
We cannot judge Hashem’s wisdom. It is not our place to question why He created the universe as He did. We certainly cannot expect to understand the reason for a person passing at a particular moment and not at some other time. Certainly, some deaths seem untimely to us – for example, the death of a young child. Is this death part of some cosmic plan according to which Hashem guides His universe? Is this tragedy part of some specific and detailed story that is in the process of unfolding? Who is haughty enough to claim that he knows the answers to these mysteries? We only know that Hashem is the Creator. He does not drowse or sleep. All that happens is a result of His unfathomable will.
Perhaps, this was Rav Huna’s rebuke. Even the mother who has lost her beloved son must accept Hashem’s judgment. It is not her place to criticize the wisdom of the universe’s design or the manner in which Hashem guides our lives. The process of mourning must include the element of tziduk ha’din – acceptance of Divine justice – even when this judgment seems to us harsh or capricious. Our refusal or failure to be consoled reflects the imaginary view that things could have been otherwise – that there is some alternative to the will of Hashem. Maimonides refers to this perspective as foolish.
7. The Talmud and Maimonides present complimentary perspectives
In summary, the Talmud is dealing with both aspects of mourning in its restriction against excessive mourning. Excessive mourning is not an appropriate tribute to the departed. Neither is it a fitting expression of personal loss. The Talmud communicates explicitly that it is not an appropriate acknowledgment of the departed by explaining that the practice implies that Hashem’s standards are inadequate. It communicates its criticism of extended grief through its account of the bereaved mother.
Maimonides’ intentions are now clearer. He does not intend to argue with the Talmud. He is focusing on the inappropriateness of unbounded grief. Through referring to the practice as a misguided aping of foolish practices, he alerts the reader that this practice is at odds with the Torah’s more enlightened understanding to life, death, and Hashem’s ways. Rabbaynu Moshe ben Maimon (Rambam / Maimonides) Sefer HaMitzvot, Mitzvat Aseh 37.  In his Mishne Torah, Maimonides does not cite the above pasuk but instead identifies an alternative passage as the source of the mitzvah.  Mesechet Mo’ed Katan 27b.  Rabbaynu Moshe ben Maimon (Rambam / Maimonides), Mishne Torah, Hilchot Availut 13:11.  Rabbaynu Yosef, Bechor Shur, Commentary on Sefer VaYikra 10:6.