Holmes deduced that The Red-Headed League did not exist, and it was actually nothing more than a ruse to get Mr. Wilson out of his shop so Clay and his accomplice could dig a tunnel.
Mr. Wilson came to Sherlock Holmes upset and confused because his employer had closed up shop. It turned out he had answered an advertisement for men with red hair, supposedly from The Red-Headed League. He was hired to sit in an office and not leave, doing nothing but copying the encyclopedia.
Holmes took the case, because he knew something strange was going on. He visited the shop, and realized that it was near a bank. He knew then from the dirt on the assistant’s knees and the hollow feel of the ground that someone was digging a tunnel.
Watson was really confused, especially when Holmes confirmed his deduction by tapping on the pavement with his stick.
Finally he returned to the pawnbroker's, and, having thumped vigorously upon the pavement with his stick two or three times, he went up to the door and knocked. It was instantly opened by a bright-looking, clean-shaven young fellow, who asked him to step in.
Holmes said that John Clay was a notorious and brilliant criminal. He arranged for the police to meet him in the bank, having deduced that the tunnel was done and the men would act soon. The police came, and they caught the robbers red-handed as they tried to break in.
It took not just amazing attention to detail but an intimate knowledge of the London criminal scene to catch Clay. Holmes knew who he was dealing with at once. He realized Clay was smart, and deduced the best way to catch him- or at least the most exciting!