Sherlock never trusted Mary. From the moment he met her, he could tell that there was something she wasn't telling anyone, a deep, dark secret.
The only reason Sherlock didn't reveal Mary's secret earlier was because he could see how happy she was making John, and Sherlock didn't want to put John through the pain of losing someone close to him again.