It could be a few things.
1. The battery could be ready to die, holding a lot less of a charge than the system shows it as holding, which would make it turn off that way.
2. You could have an app (some phones do, some don't) or a setting that turns it off automatically when it reaches a certain battery percentage. You would have to change the settings for this to stop. If that is the cause.
3. There could be virus or malware on the device that is the cause. You would have to check the phone for both of these (They are very different.).
4. You have an app on the phone that is the cause. Not like listed above, but one that is just messing with the device. You will have to check for what apps are there and what they are doing. Sometimes apps get installed that you didn't put there yourself. Check for this and the settings of all apps you did install.
5. Should none of this resolve it, then the next step is a "Hard Reset". This, however, will wipe the device and start it back up as it was originally (before use). Should you choose to do this step, then be sure you back up all your personal information either to a cloud account, google account or a computer. Files, contacts, pictures, etc., but not apps, they cannot be backed up.
6. And if all of the above doesn't fix the problem, then if under warranty contact the manufacturer about a repair. If not under warranty, then you can try a local tech.