It will turn off if the battery gets too low. It will also turn off by itself if there's something wrong with it.
There's a problem that combines both off the above. If the battery has a particular defect called a dendritic short, it will short out after a few hours of use. (How long depends on the short - it could be from less than an hour to many hours.) That shuts the phone off, but also burns the short out. The next time you turn the phone on, the same thing happens - the dendrite grows until it causes a short, burning the short out and shutting the phone off. If you install a battery monitoring app that keeps a graph, you'll see it. The battery voltage dropped to 0 when the phone shut off.
This is actually a manufacturing defect (there was an impurity - usually a spec of dust or a human hair - in the battery when it was being made), but good luck trying to get it replaced under warranty.