he might have already been in your office. according to the original Fnaf 1s code, he has a 25% chance to attack every second after he enters your office. if you are sure he was not in your office before you closed the door it was likely a bug