class enum was not declared in this scope
This is a known bug of Arduino builder, if you have functions before structs, classes or enums in sketch.
The sketch:
void foo() {
}

enum class CYCLE { TypeA, TypeB };

String cycleToString (CYCLE cycle) {
  if (cycle == CYCLE::TypeA) {
    return &quot;TypeA&quot;;
  }
  else if (cycle == CYCLE::TypeB) {
    return &quot;TypeB&quot;;
  }
  return &quot;Undefined&quot;;
}

void setup() {
}

void loop() {
}

is processed to this .cpp file
#include &lt;Arduino.h&gt;
#line 1 &quot;/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino&quot;
#line 1 &quot;/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino&quot;

#line 2 &quot;/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino&quot;
void foo();
#line 7 &quot;/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino&quot;
String cycleToString(CYCLE cycle);
#line 17 &quot;/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino&quot;
void setup();
#line 22 &quot;/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino&quot;
void loop();
#line 2 &quot;/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino&quot;
void foo() {
}

enum class CYCLE { TypeA, TypeB };

String cycleToString (CYCLE cycle) {
  if (cycle == CYCLE::TypeA) {
    return &quot;TypeA&quot;;
  }
  else if (cycle == CYCLE::TypeB) {
    return &quot;TypeB&quot;;
  }
  return &quot;Undefined&quot;;
}

void setup() {
}

void loop() {
}

as you can see the forward declarations of functions are before the first function so before the enum.
The workaround for this bug is to follow good practice and declare all the structs, enums and classes before the first function definition.