Maupassant was not a moralist but a realist. What happened to Mathilde Loisel was just bad luck. She lost the borrowed necklace. She was not being punished. There are no unwritten laws decreeing that women will be punished for wanting to be admired or for borrowing necklaces. We do not feel that Mathilde was doing anything wrong when she bought a new dress or attended the ball or borrowed the necklace. Her only mistake was probably in not going to her friend and telling her she had lost the necklace. Then she would have found out the truth--and maybe the "moral" of the story is that people should face up to the truth, even when it is painful. Instead, it takes her ten years to realize that the necklace was made of fake jewels. Even then, it is only by sheer accident that she runs into Mme. Forestier when she does. Mathilde's fantasies and dissatisfactions were not of her own creation. The newspapers and magazines were largely at fault for making women experience "heartbroken regrets and hopeless dreams." They secrete a slow poison that cause incalculable amounts of trouble.
It's really easy to kind of "beat up" on Mathilde. She is not a laudable or commendable person in any way for most of the story. Her so-called punishment is the years of hard work and deprivation it takes to pay off the Loisels' debt. Whether or not she deserves that is really not the point. It happened and she's better off for it. I suspect Mathilde herself would say she was thankful for the lessons it taught her.
Certainly M. Loisel did not have the life she expected, but if you read the ending of the story, there is a quiet sort of pride that she has found in herself as she has worked so hard to achieve the goal of paying off the necklace. I would suspect she and her husband have a more meaningful relationship too as she recognizes the value and results of their hard work together.
It is true that she is guilty of pride--hubris, the Greeks called it. Excessive pride which is the downfall of the hero in the story. Had she simply admitted to her friend that the necklace was lost, Madame Loisel and her husband would not have spent the next several years toiling away working overtime in order to purchase a genuine diamond necklace as a replacement for the fake one. Had she simply admitted her fault, her friend most likely would have told her then that the necklace's gemstones were imitation.
While Madame Loisel's lesson was a hard one to learn, I'm not certain she deserved the consequences. On the other hand, given her character and personality, I'm not certain she would have learned the lesson so effectively had she confessed and simply paid for an imitation necklace replacement.
Whether or not she received appropriate retribution for her excessive pride depends on who is judging. Consider not only her desire for material welath but also her more subtle intentions. Her material desire symbolized a want for a different life -- a more significant social status. Remember how she looked at other powerful figures in society and the dreams she had of their courtship. She never dreamed only of those men meeting her excessive material needs and not her emotional needs. Her husband, although poor, cared deeply for her and did everything in his power to make her happy. Nonetheless, she would have seemingly left him for the person who could meet any of her above desires.
Her dreams and desires are not unlike those of many people and it is easy for someone to succomb to the temptations of material wealth and all accompanies it. Thus her retribution could assessed as excessive. However, before she lost the necklace, she had a loving husband and her basic needs were all met. If the reader's ethical stance values marriage and emotioanl well-being, then her retribution can be viewed as light. Clearly, judging whether or not the retribution was just depends on the person.