Why is my MacBook falling asleep with "Clamshell Sleep" but lid is not closed I have a MacBook Pro (Retina, 15", Mid 2015) running El Capitan (10.11.6).

It will often run for days with no issue. I will be using the Mac at the time, then suddenly the screen shuts down black as if its gone to sleep (nothing that I've done knowingly has triggered this). There is nothing that I can do to then turn on the Mac - Power button does nothing and pressing the touchpad also does nothing. I have to close the lid and then open it again to wake it up.

When I then open up the Mac, it will stay awake and then repeat the above over and over, only staying awake for 5 - 15 seconds at a time before sleeping again.

I have run:

    pmset -g log


.. and i get (amongst all other lines)

    Entering DarkWake state due to 'Clamshell Sleep': Using AC (Charge:100%) 


From all my Googling, this seems to indicate that the lid has been shut, but the lid is still open.

Any hints on how I can stop this from happening?

ALSO: This is the 2nd MacBook Pro this has happened to, so seems to be a user profile or software thing over a hardware thing. This issue has followed me moving from one machine to another with a Time Machine backup...
I don't know if this might be pertinent to your situation, but I once had a very similar problem with a 2009 MBP. The weird thing was when I picked it up and moved it, it would wake up. This went on for weeks until I finally figured it out; it would sometimes fall asleep when I put it on top of a (closed) white MacBook. It turns out both the MB and MBP sense the lid is closed via a magnet in the lid and a magnetic sensor near the front of the machine. When I laid it on top of the MB the MB's magnet triggered the sensor in the MBP making it think the lid was closed. So, it might be worth noticing if you've got any strongish magnets in the area around the front of the machine when it spontaneously takes a nap.