Who exactly is ghost!Mary?
She is certainly not Mary the cold-blooded operative/assassin Rosamund, nor the woman who shot Sherlock in order to perpetuate the lie and keep John's love. She isn’t even the sweet, sometimes impish Mary who loves John and Sherlock. There is a softness to her, a gentle, loving Mary full of wisdom and a sense of peace. This is not the Mary we knew.
She is what is called in guided imagery circles, an Inner Advisor. (Inner Advisors go by many names, e.g., as inner guide. These should be differentiated from Spirit Animals or Spirit Guides.) It’s a natural process that children do all the time with their Imaginary Friends. Adults usually need more help, but occasional an IA appears spontaneously.
In a specific kind of imagery practice called Interactive Guided Imagery™ (IGI)*, the premise of an Inner Advisor is that we all have wisdom and knowledge inside us that we may not even realize we have. Think of it as a locked Mind Palace of wisdom. We sometimes access it by chance (if such a thing exists), but the Inner Advisor (IA) lets us in on demand. As Sherlock said of drugs, they "opened doors in my mind." IAs let us do that, too.
Just like Fake!Faith, IA!Mary is "a magic woman who told you things you didn't know." By her saying, "Well, sounds about right to me. Possibly, I'm biased," she admitted as much.
An Inner Advisor, by definition, must be loving, wise, know you well, and have your best interests at heart. Real!Mary sometimes exhibited these qualities, but an IA must personify them at all times. An IA also has special knowledge of the particular problem/issue confronting you at the moment and be willing to communicate that information to you in a way you understand, usually through internal speech, but often non-verbally.
Are IAs of a person the real person? No. Imagery is the language of our subconscious. IA!Mary pleads with John to make the distinction that she is not Mary. Mary’s dead. This is an image of Mary, a representation of her higher self, filtered through John's subconscious.
IA!Mary in The Lying Detective is definitely loving and knows John to a T. At every turn, she offers wisdom regarding himself, his relationship with her, and his relationship with Sherlock; she also urges him to take action when he hesitates from what he knows he should do, as in coaxing him to ask Mycroft about "the other one" or going after Mrs Hudson.
It is significant that in the mortuary scene when John beats the hell out of his best friend, IA!Mary is nowhere to be seen. As others on tumblr have said, and as Martin Freeman confirmed in his PBS interview, John blames himself for Mary's death -- maybe not consciously, yet -- and takes his rage out on Sherlock. There is no Inner Advisor at work here because rage is overriding everything else. This is all about "self-loathing," to use IA!Mary's words.
Self-loathing, self-destructive behavior, and mentions of suicide are recurring themes in this episode for both main characters, ranging from John's drinking in his hallway in the middle of the night, to Sherlock's drug use, even if done in self-sacrifice to save John. Assuming he is right, there is also Eurus's self-harm cutting that Sherlock deduced.
It is also significant that IA!Mary is silent when John confesses his infidelity. He is far from ready to forgive himself yet, and the self-loathing is blatant in this scene. He is not ready to hear anything IA!Mary might say; just because IAs are all-loving does not mean they can't cry.
IAs are not separate from ourselves; quite the opposite. They are our best selves. IA!Mary is not trying to make John a better man. The better man is already there, awakening ("John, do better.") She encourages him with a perfect call to action: "Get the hell on with it."
____________________________________________________________
* Interactive Guided Imagery a technique trademarked by The Academy for Guided Imagery in Malibu, California.
For another use of guided imagery advisors you might want to read the amazing sevenpercent's "Magpie: One For Sorrow." Chapter 10 is where Sherlock's inner advisor is identified.