The title, The Lying Detective (2017), is based on the name of a Sherlock Holmes short story titled "The Adventure of the Dying Detective"; and, as in this episode, the antagonist is Culverton Smith (Toby Jones).
During Sherlock's outburst inside his room, his quotes were taken from William Shakespeare's "Henry V" ("The Life of King Henry the Fifth") inspired by Henry V himself. The entire quote can be found in "Scene I: France. Before Harfleur." This scene also contains the quote "The game's afoot!"
Five years before this was made, England was shaken by the postmortem revelations about Jimmy Savile. For decades Savile had been one of the most popular and beloved BBC program hosts, knighted by the Queen, and a respected philanthropist. After his death it came out that he was probably the most prolific child rapist in English history. For many years the people around Savile had ignored the strong evidence of his horrific crimes.
Sherlock's line, "Your life is not your own. Keep your hands off it" is taken from the short story, "The Adventure of the Veiled Lodger".
Culverton Smith appears to be influenced by Jimmy Savile. Smith has a Yorkshire accent, wonky yellow teeth, appears in a cereal advert (Savile voiced a Sugar Puffs advert in the 1980s), frequently visits ill children in hospital (Savile became 'honorary entertainments officer' at Broadmoor, the high-security mental hospital), and has access to a corpse. (Savile reportedly 'interfered with bodies of deceased patients' and once stole a glass eye from a corpse, which he wore in a necklace.)