When the battery dies the power chip gets confused.
My iPhone 6 needed a battery replacement just short of two years and had the same symptoms - the battery indicator would show plenty, but at some random point it just turned off. I was trying to limp along like that until the 7 came out but it continued to deteriorate. $65 and an hour at the Apple Store and all was great again, and now I'll wait for the iPhone 8. I use the phone heavily and often charge during the day, it was up over 700 load cycles when it failed, so I'm not too upset. I've had iPhones since day 1 and never had any trouble before.