Why on earth would Sonya write such a letter, you ask?
Well, her life with the Rostovs is hard. Remember, she’s dependent on them for practically everything and is a second-class citizen in the family. (She’s just a relative they’ve taken in.)
Most of her life, she’s been all too happy to self-sacrifice and generally be mistreated, because in her head this just made Nikolai love her all the more.
But now, suddenly, Countess Rostov keeps making snide comments about how she’s tied Nikolai down and how he can’t marry Marya like everyone wants, and generally making Sonya's life miserable.
For a while, Sonya plans to secretly tie Nikolai to her even more. (Maybe through a secret wedding? It’s not really clear what this means.) But now that Andrei is with the Rostovs, she’s got another plan going. She figures that Andrei will recover, and that he and Natasha will fall back in love and get married. If this happens, then Nikolai and Marya won’t be able to get married because it would be considered incest. (Wait, so first cousins getting married is no biggie, but people related only by marriage getting married, that’s incestuous? Oh, you wacky 19th century people.)
Meanwhile, the Rostovs are staying in a monastery. Andrei seems to be doing better, and Natasha is happy because of all the love. When Sonya peeks in one day, she sees Andrei sitting propped up on some pillows and it reminds her of what she pretended to see in the mirror fortune-telling game. Creepy.
Anyhow, because she has this theory about Natasha and Andrei getting married, Sonya is all too happy to finally oblige Countess Rostov’s pleading and writes the letter to Nikolai ending their engagement.