Diagnosis
The door switch assembly is failing. It's a mechanical plunger switch that tells the control board the door is securely closed. If the plastic housing cracks or the internal micro-switch wears out, it makes poor contact.
How to Fix It
You need to replace the door switch. Unplug the dryer. The switch is mounted inside the front frame, right behind the door opening. You'll need to remove the top panel and possibly the front console to access it. The switch is held by a couple of screws and has a wire connector. Before you buy the part, manually press the switch plunger with the door open and listen for a distinct 'click'—if it's mushy or silent, that's your culprit.
If That Didn't Work
If a new switch doesn't fix it, check the alignment of the door itself. The strike (the metal tab on the door) should hit the switch plunger squarely. If the door is bent or the hinges are loose, the strike might not be engaging the switch fully.
Heads Up
Don't try to bypass the door switch to make the dryer run with the door open. The drum shouldn't spin with the door open for safety reasons, and bypassing it can damage other components or create a hazard.