Diagnosis
The lid lock assembly (or latch) is failing. It's trying to lock but can't complete the cycle, so the machine refuses to run for safety.
How to Fix It
Unplug the machine. Inspect the metal strike on the underside of the lid and the plastic latch on the washer top. Make sure there's no obvious obstruction (like a sock tag) and that the strike isn't bent. Manually press the latch mechanism with your finger to see if it moves smoothly. Plug it back in and try closing the lid firmly.
If That Didn't Work
The lid lock switch itself is probably defective. It's a known failure point. You'll need to replace the entire lid lock assembly, which is a pretty straightforward part swap once you get the top panel off.
Heads Up
Never try to bypass the lid lock. The washer won't spin with the lid open for a very good reason. Just replace the part.