.
Between the crack in the screen and this issue, methinks you need a new laptop.
Few things could be causing that
1) Something is hitting your power button to turn it off.
2) Make sure you're not wearing something magnetic that would trigger the "lid closed" sensor on the laptop while you're typing on it. If something brushes over that, the system will sense it's closed and go into sleep mode.
3) Weird OS power settings.
#2 might be the most non-obvious but likely cause.