All that is happening in this episode is nothing more than a whimsical world created by Sherlock to prove that Moriarty is dead.
JOHN: Sherlock, hang on. Explain. Moriarty’s alive, then?
SHERLOCK (stopping near the car and taking his gloves from his pocket): I never said he was alive. I said he was back.
MARY: So he’s dead.
SHERLOCK: Of course he’s dead. He blew his own brains out. No-one survives that. I just went to the trouble of an overdose to prove it.
(He throws a quick guilty look at John before looking down.)
In the entire episode we can see him hallucinating between the fantasy and the real world. This statement is just a reference to the fact that it's all in Sherlock's Mind Palace.
MYCROFT HOLMES: Yes. He’s the crack in the lens, the fly in the ointment ... the virus in the data.
(Lowering his hands, Holmes turns round and looks sharply at him.)
The sharp look that Sherlock gives is also suggestive of the fact that he himself is baffled by this statement in that time period.