Mac turns off randomly and has lines on screen
On first guess, based on the description of the symptoms, I would say that you are having an issue with your graphics card.

The best way is to run Apple Diagnostics or Apple Hardware Test. Hold D while booting from a powered off state.  Run the diagnostics and post your results and I will update my answer.

First update based on the comments:  I found this video on YouTube that details this exact problem and it's related to the graphics card.  Now, one word of advice: don't do the fix shown in the video.  

While the diagnosis is correct, that fix is pure nonsense.  I have had much better results getting the board repaired by a shop that specializes in that type of fix (from eBay - I have used the one in Dana Point, CA with great results and for the record, I am not affiliated with them).  

Normally I would say to replace it, but the prices are ridiculous - sometime over $700 for the graphics card.