All batteries, regardless of type will experience something called voltage sag. Heck, you even see this with your AC power for your home when the lights dim for a split second whenever something like the air conditioning kicks on and draws a lot of power.
In short, any time a demand is placed on the battery, the voltage will drop for a bit. This is natural and to be expected, but the amount of voltage loss is minimal on a healthy battery. As a battery ages and the internals breakdown, the amount of voltage loss increases. The amount of demand you put on the phone affects this as well. I.e. Gaming would result in more of a voltage sag than just sitting idle.
What makes Li-ion batteries unique is that they can not be discharged to 0 volts and then recharged (at least not without special care and equipment, and even then it's not guaranteed). 0% on your battery gauge is not zero voltage. It's the lowest the battery can go and still be safely recharged.
So what you are experiencing is what happens when these two issues intersect. As your battery gets low, something is putting a power demand on the weakened battery that causes the voltage sag to dip below the cutoff point. When this happens, it's an instant shutdown as if you pulled the battery. This usually isn't noticed at first because it may start at 5% or so, which most people would've already plugged in before then. It'll only get worse from there. So you keep using your phone not knowing this is getting worse and worse, except maybe for shortened usage time between charges, until it finally starts sagging so much that the cutoff happens before you'd plug it in.
Hopefully this helps clear it up for you. As a side note, this instant shutoff is what Apple was trying to avoid when they started slowing down their phones with weak batteries. By throttling performance, the voltage sag wouldn't be as bad, letting you keep using the phone longer without the instant shutdown. Not that this is necessarily a good thing, as Li-ion batteries hate being deeply discharged and letting people keep doing so like this could actually speed up the degradation.