Okay, I don’t think it was ever said, but like here, here is where the headcanon I have that Sherlock has slight social anxiety. It’s not bad enough to the point that it renders him dysfunctional, but enough so that scenes like this, right before he walks into a huge crowd, he needs a second. You can see it- John asks him if he’s okay, and he shuts his eyes tight and nods.
Also, John by now is a bit of a caretaker for him, and maybe he told John about it and it helps because John is always with him, and checks on him a lot and asks if he’s okay and sometimes Sherlock gets nasty and snaps (“I’m not a child, John!”) but then scenes like this comes along and just for a moment, Sherlock looks like a scared little about to face his fear and this just makes me so happy (^ω^)