De 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.
Como a Wikia é, bem, a Wikia, aqui está um link para uma transcrição mais confiável do episódio: link