Från wikia :
In the episode "The Hot Tub Contamination", the origins of this knocking ritual are revealed. When Sheldon was 13 years old, he once came home because they ran out of math to teach him. His mother was at a Bible study. He walked in the house expecting it to be empty and heard a sound from his parents' bedroom. When he opened the door, he saw his father having relations with another woman. It’s why he never opens a door without knocking three times. The first one is traditional, but two and three are for people to get their pants on.
Eftersom Wikia är, ja, Wikia, här är en länk till ett mer pålitligt transkript av avsnittet: länk