Galaxy S4 Turns Itself Off

I have done the appropriate Googling on this, and this appears to be a problem that many people have had. It also appears to be a problem with multiple causes. Some folks have solved it by getting a brand new battery, others by doing a factory reset. I am putting my experience here to see what Dopers have to say about it, if anything.
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. If there are any other solutions, I would like to hear about them.

Instead of thinking of it as a function of compression, think of it as something in that vicinity that is shorting out, which is by far more likely. See if you can slip some tape/paper/plastic in between the likely culprits, and hopefully you can fix it with some trial and error.

That’s a good idea. However, in order to do that, I would likely have to disassemble the phone to some extent. The S4 is reportedly fairly easy to work on, but my experience is that something always goes wrong when you do this (usually stripping one of those tiny screws). I will think about it.

Hopefully, you won’t have to disassemble any more than you already have. It seems likely that the short is between the micro-SD card holder (you said SIM card holder, but are you sure you didn’t mean SD card?) and whatever it’s touching below it (the circuit board?), or above it (the battery?). If you can slip something in between the SD card holder and whatever it is touching (on both sides, even if it’s temporary), and the problem goes away, at least you’ve narrowed it down.

Speaking of which, does the phone have the stock, OEM battery, or is it aftermarket and/or thicker than stock?

It is the sim card holder. However after a little more experimentation, I find I can duplicate the problem by pushing down near the sim card, which suggests to me that the problem is on the motherboard. I am not sure I can slip anything under the sim card, but I will give it a try.

The battery is OEM.

Well, if it’s not something like one conductive component (SIM card holder?) inappropriately touching (heh) another and causing a short, and instead it’s a general area of the circuit board flexing that does it, it’s probably a teeny tiny solder joint in that area that is not reliably maintaining a connection, probably from a combination of abuse such as dropping and overheating.

No sort of return or warranty, eh?