I think a major factor is that it's hard to exit companions, especially if they don't want to leave. In New Who, at any rate; by contrast, in Classic Who, the Doctor is much more capricious, but time and tastes have moved on and I think the showrunners believe (and rightly) that the Doctor just dumping a companion would not be taken well by the audience, for whom, after all, the companion is a sort of stand-in.
In the case of Martha, she willingly leaves, and it's believable that she would, partly because her relationship with the Doctor has run its course (they've been separated for a year, she realizes her feelings are unrequited), and because she and her family have been through a series of incredibly traumatizing events. She wants to be there for them. The audience understands.
Rose, through mischance, winds up trapped in an alternate universe. It's not the Doctor's fault.
So when it came to Donna, it was tricky to write her out -- unlike Martha, she had no interest in leaving. So they gave her a more Rose-like exit, in that it becomes impossible for her to continue travelling with him. But aside from killing her (which would have precluded ever having her in the show again and probably seemed unnecessarily harsh to the writers in the RTD era) there wasn't a lot they could do without having the Doctor just leave her, or a verbatim reprise of Rose's story. So they took her memories instead.
I agree it's sad, and I think it was meant to invoke a sense of pathos rather than the anger it did -- for a very brief moment, this deeply insecure woman is the most important woman in creation and knows it. I think the writers underestimated how angry that would would make some audience members feel on Donna's behalf.
If you're asking why write Donna out at all, it was simply part of wrapping up RTD's run, tidying away all the story threads before handing over to a new showrunner. Could they have done it differently? Yes. But they were in a tricky position.