Sherlock Holmes makes this particular comment in regards to a note that Mary left behind for her uncle, Mr. Holder. In this note, she reveals that she was going away on account of a statement her uncle had made to her, which was essentially blaming her refusal to marry his son on the misfortune that had befallen their family. It is this decision to abandon her uncle in this fashion that Holmes refers to as "the best possible solution."
The details of the case run as follows: Holder had been entrusted with the beryl coronet to serve as collateral for a loan. Because of its importance, he decided to keep it with him at all times rather than continue storing it in a bank vault. However, a crime is committed, and Holder finds his son holding the damaged coronet, with three gems having gone missing.
Holder believes his son is the culprit, but Holmes discovers that the guilty party is actually Mary, who had been in a relationship with a man Holmes describes as "a ruined gambler, an absolutely desperate villain." Thus, Holmes thinks it's for the best that Mary make her departure in this manner, given the degree to which she has betrayed their trust by collaborating with the attempted theft of the coronet.