That seems to be a gratuitously complicated method of implementing a "state machine".
Perhaps your problem is related to using Strings.
The other part of the code that looks dodgy, is where you attempt to read the string from the serial. What do you expect the readStringUntil() function to do, exactly ? Is the other end of your serial communication sending the newline character that you expect ? You might have fallen into some version of the CR vs CR-LF problem.