Stuck with program flow and freezing programm

If these still cause you to run out of memory, you need an Arduino with more memory.

Point taken.

However, I am still looking for a explanation why everything was working fine with having this bit of code 9 times in the main loop:

     if(switchState[0] == 1 && lightStatus[16] == 1) {            //checking if PIR in Room 1 was
                                                                   //activated (bed 1)
         lightStatus[16] = 0;                                      //resetting master off
         digitalWrite(doorMonitor, LOW);                           //resetting the door Monitor LED
      }
     
      if(switchState[1] == 0 && sensorValue <= photoCellCutOff) {  //checking if S2 priority off was
                                                                   //set bed 1
        if(switchState[0] == 1 && priorityStatus[0] == 0) {        //check if the PIR in bed 1 was
                                                                   //activated and no priority was set
           //Serial.println("We switch in the lights in bedroom 1");  //Debug only
           lightOutput[0] = 1;                                     //switching on the lights – binary
                                                                   //000000000000000000000001
           lightStatus[0] = 1;                                     //setting the light status for bed 1
           lightOutput[14] = 16384;                                //make sure the master relay
                                                                   //stays on
           lightStatus[14] = 1;                                    //setting the master yelay status
           roomTimer[0] = millis();                                //setting the timer
        }
        else if(switchState[0]  == 0 && lightStatus[0] == 1) {     //the PIR not activated but the
                                                                   //lights are on
           //Serial.println("We are checking the timer");            //Debug only
           currentTime = millis();                                 //setting time reference
           endTime = currentTime - roomTimer[0];                   //calculating the inactive time
           if(endTime >= delayTime[0]) {                           //comparing inactive time with
                                                                   //allowed delay time
              //Serial.println("Time is up switching off the lights");  //Debug only
              lightOutput[0] = 0;                                  //switching off the lights
              lightStatus[0] = 0;                                  //resetting the light status
              roomTimer[0] = 0;                                    //resetting the room timer
           }
        }
     }
     else if(switchState[1] == 1 && lightStatus[0] == 1
             && switchState1Old != 1) {                            //if priority is activated and the
                                                                   //lights are on
        //Serial.println("Priority switch activated switching off the lights");  //Debug only
        lightOutput[0] = 0;                                        //switching off the lights
        lightStatus[0] = 0;                                        //resetting the light status
        roomTimer[0] = 0;                                          //resetting the room timer
        priorityStatus[0] = 1;                                     //setting the priority status bed 1
     }
     else if(switchState[1] == 1 && lightStatus[0] == 0
             && switchState1Old != 1) {                               //if priority was activated and the 
                                                                   //lights are off
        //Serial.println("Priority switch deactivated switching on the lights");    //Debug only
        lightOutput[0] =1;                                         //switching on the lights
        lightStatus[0] = 1;                                        //setting the light status
        roomTimer[0] = millis();                                   //setting the room timer
        priorityStatus[0] = 0;                                     //setting the priority for bed 1 back  
     }
     switchState1Old = switchState[1];                             //passing on the switch state

and after I placed it in a function, having it only once and the respective function calls I am getting the memory problems.