Diagnosis
The door latch mechanism is likely jammed with a small piece of debris (like a broken plastic fork tine or a seed) or the strike plate on the tub is misaligned. It's a physical blockage preventing the hook from engaging.
How to Fix It
Unplug the dishwasher. Shine a flashlight into the latch receptacle on the front of the tub (the square hole where the door latch clicks into). Look for any foreign objects. Use needle-nose pliers or a toothpick to carefully remove anything you see. Next, inspect the actual latch hook on the door itself for damage or obstructions. Manually move the hook with your finger to see if it springs back freely.
If That Didn't Work
If the latch moves freely and the path is clear, the strike plate (the metal piece around the tub's latch hole) might be bent or out of alignment. You can slightly loosen its screws, tap it into better alignment with the door closed (but not latched), and then re-tighten. Be gentle—it's thin metal.
Heads Up
Don't force the door closed. If you slam it hard enough to engage a jammed latch, you can break the plastic latch assembly or the door hinges, which is a much bigger repair. The machine is designed not to run if it doesn't sense a proper latch, so forcing it won't help anyway.