Rotary encoder, with single-, double-click, hold and rotation.

Couple of thoughts :

if your Serial.printing() stops completely, but your keycode are still sent, it feels like memory corruption is happening. You have declared encoderLastValue as long, but your encoder0Pos as int. You compare those and store values. Maybe try to define them both the same.

your encoder pins do not seem to have a pull-up or pull-down internal resistor set. Is that what you wanted ?

Not sure why it the check-button, when handling the encoder change on different places, it is also sets values that are only relevant to the button ( DCwaiting = false;, singleOK = false; DConUp = false;)

Looks to me that the encoder pins input have nothing to do with the button pin. There might be a better ways to handle. If encoder change is detected, handle that in check-button() completely in the beginning and return. If no encoder change, skip that code and handle the button. Otherwise I would make it 2 separate calls, one to check for the button and one to handle the encoder.