I suspect that we are talking about multiple problems with the same symptom, but I will add my experience and see if anybody can profit from it.
I bought my S4 on Swappa (AT&T SGH-1337). It was represented as "in mint condition", and when I got it, it worked fine. One thing that was odd was that it came in an aftermarket metal case of the kind that sell on ebay for 8 bucks. After a day or two, it started turning off when left in my pocket. I took the case apart (it requires unscrewing tiny screws). The phone did not have the stock plastic back on it (this was supplied elsewhere in the box). I replaced the stock back and it immediately began turning off more often. After some experimentation, I discovered that I could duplicate the behavior (phone turning off) by squeezing the phone. If I took the back off, I could turn it off by pressing on the sim card holder. I think that the guy who sold it on Swappa provided the aftermarket case to make this less likely. One thing I found was that if I removed the back and left it out of the metal case, it seems to work reliably (no turning off). This is not, however, a long term solution. What I intend to do is to glue a tiny spacer to the plastic back to prevent the sim card holder from being compressed. I am not sure this will work as the back fits so snugly, but I will give it a try. I will let you know what happens.