shahram,
It sounds like you're encountering a little static electricity (or electrostatic discharge, if you want to be fancy about it). The reason your getting "logged out" is probably that the ESD is causing a power surge that makes the laptop think the lid was closed (you're getting current from a sensor that isn't actually the source of the current).
It's best not to sit electronics on soft surfaces such as beds, carpets, etc as ESD can damage the hardware if a charge with too strong a current goes through it. If you've ever gotten a good hard shock when you touch the door knob after walking across the carpet in socks, you know what I'm talking about. :-)
Too more directly answer your question "How do I correct this?", the obvious answer is the best one: don't put your laptop on your bed. Make sure you use a laptop desk (something like this: https://www.officedepot.com/a/products/781650/Lap-Desk-Originals-Student-Lap-Desk/ or even a simple board so the computer is sitting on a smooth hard surface where it won't be affected by static, and will much more easily cool itself. (Sheets don't just hold static, they hold heat too.)