If you remove the right hand battery and peek in with a flashlight, you can see a tiny bat-handled microswitch directly under the latch slot that senses when you have fully closed the cover. Slamming the cover, or better just pressing more firmly further compresses the rubber bumpers to the left and right of the latch mechanism and allow the latch to penetrate a bit further to actuate the microswitch. First check to see that both top cover bumpers are fully inserted in their niches and that the latch extends about .300 inches from the sloped cover face. The latch foot should be a smooth J curved shape, not flattened or fractured/foreshortened. Check that the microswitch is mounted flush to its PC board, that the top corner almost touches the palm rest underside rib, and that the carrier board triangular section towards the upper rear is screwed firmly to the plastic mount area near the trackpad. If the microswitch works but the mechanical tolerances are marginal for trip, you can fudge things a bit by resoldering the switch to stand a little taller. Fortunately you can see the action with the battery removed, and shim the penetration to determine how much more you need or if a new switch is needed. It could also be an electrical intermittent, but start by seeing if the switch reliably sleeps the machine if you trip it mechanically by reaching into the open right battery bay.