You have a static 'state' variable that is initialised to 'S_seriesAOn'. So regardless of the sensor reading, it will start the statemachine the first time. You can solve this by creating a statename (e.g. something like S_stopped) that is not used in the switch/case and using that as the initial value.
if ((cm <= 40) && (cm >= 2)) //if sensor is triggered, start the state machine
{
Serial.print("starting state machine");
state = S_seriesAOn;
}
This will reset the state to S_seriesAOn as long as the distance is in the specified range (regardless of the next state that is set in the switch/case).
I think that your original approach where you tested the sensor inside the statemachine was far better.
The reading of the sensor can be outside the switch/case but the test will be inside a case.