In the episode “The Hot Tub Contamination “, the origins of this knocking ritual are exposed. When Sheldon was 13 years old, he once came home because they operated out of math to teach him. His mom was at a Bible analyze. He strolled into the house expecting it to be empty and heard a audio 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 doorway without knocking three times. The first one is traditional, but two and three are for people to get their pants on.