The scene between Sherlock and John, where Sherlock is having an emotional break down in "Hounds of Baskerville", is similar to a scene in an episode of Star Trek called "Naked Time" where Spock has an emotional break down and confesses to feeling shame when he feels friendship towards Jim Kirk, his captain and best friend. In "Baskerville", Sherlock angrily tells John Watson, his best friend, that he has no friends. Both characters say that they have to control their feelings. And both break downs are caused by a drug like substance. Sherlock was reacting to the drug mist. Spock to a space disease that made one act intoxicated.
The character of Spock is similar in many ways to Arthur Conan Doyle's Sherlock Holmes, so I think the writers were borrowing back as a joke, and that's why John calls Sherlock "Spock" because he is acting like the famous Star Trek character. Sherlock and John, Spock and Jim, even the names are similar.