So I know that Matilde changed after she had to work to pay off the debt that she had with her husband, but Matilde struck me as the type of person who would have left her husband with all the debt and went her own way. I guess I just don't understand what actually caused the change of heart.
Having been a clerk in the Naval and Education Ministries in Normandy himself much like Mathilde's father, Maupassant witnessed firsthand the pettiness of the bourgeosis. And, it is this unreasonable pettiness that he wishes to portray through the character of Mathilde Loisel. It is this pettiness that prevents Mme. Loisel from telling Mme Forrestier the truth about the necklace. Instead, she uses her husband to help her finance the duplicate.
Mathilde was raised in a hardworking, poor family. (At least poor compared to her married life) As a woman of that era, she would have had few options but to stay with her husband or be shunned and live a life even more deplorable than the one she found herself in. However, her "change" was not sudden. It evoked ore a ten year period while she and her husband were sharing a common goal. this led Mathilde to a sense of pride and accomplishment which she'd never had before.
The root of Mathilde's problem is a general discontent with what she has--she always wants more. Mathilde is particularly stubborn in her dissatisfaction, which may actually cause her to simply dig in and do what it takes to eliminate the debt she created. Perhaps, too, her shame at being poor prepares her for the shame of being even poorer.
I agree with Post #2 that Matilde would not have been able to do any better for herself if she had left her husband. That, presumably, plays a major role in her staying with him.
I would also point out that it probably never occured to her to leave him. Divorce, as Post #2 says, was simply not an option for most and so she probably wouldn't have thought of it at all.
Finally, I do think she is childish and spoiled in the rest of the story, but there is nothing to suggest that she does not love her husband. I'm not saying she's madly in love with him, but we never see her criticizing him for the way they live or anything like that. She wishes she were richer, but she doesn't tell him "how come you can't get a better job" or "it's your fault we're not rich." So maybe she really does like/love him.
I think we need to remember the context in which Guy de Maupassant was writing. Let us not forget that actually in those days women did not have as many options or opportunities as they do today. Divorce was only really an option for the rich and upper-class, if at all. If Mathilde had left her husband, it would have been for a far worse existence. You are right, however, in pointing towards a sudden change of character, especially expressed in these lines:
Mme. Loisel experienced the horrible life the needy live. She played her part, however, with sudden heroism. That frightful debt had to be paid. She would pay it. She dismissed her maid; they rented a garret under the eaves.
What we do see in this section is that finally Mathilde begins to grow up and mature, leaving her daydreams behind her. The story does seem to need or require a big shock that would force Mathilde into such action. The constant daydreams that she has at the beginning of the tale show her lack of maturity and realism. Realism is something that this new Mathilde definitely does not lack, and this is heightened by the grimly humorous ending of the tale.