In Hello Neighbor Search & Rescue, if you for example try to put in the fire code before reaching the room you find it in, it would just not accept it and act like you put in the wrong code, basically just bring that over to this game. Here are the conditions you would need to meet in order to be allowed to put in the code.
For code in Mr. Petersons house you would need to see each cube and then you could put it in.
For Otto's house you would need to place all pieces of the map to be allowed to put in the code.
for museum part 3 you would need to place the three gear in the clock and then you would be allowed to put in the code.
For the code in the mayors house you would need to place the boat on the stand to reveal the code and then you would be allowed to put in the code.