Sherlock Season 4: 18 Easter Eggs & References From 'The Lying Detective'
8. Abominable Bride Callbacks
When Sherlock still believes that he hallucinated the night he spent with the woman he thought to be Faith Smith, he suggests that the drugs he was taking further heightened his mental capacity to deduce facts and allowed him to realise things he didn't know he knew.
This recalls the events of The Abominable Bride. In the 2015 special, Sherlock experiences a drug-induced trip in which he imagines himself as a Victorian. This allows him to find the solution to the long unsolved case of Emilia Ricoletti.
In this same scene, Sherlock says to John: "I'm Sherlock Holmes. I wear the damn hat." It is possible that he remembers John saying something similar to him in his Victorian dream from The Abominable Bride: "You're Sherlock Holmes. Wear the damn hat!"