Why does my phone automatically power off when there is still 2% battery? My Moto X Play on Android 6.0 would automatically power off when the battery displays 2% remaining. When I try to turn it back on, I would get a "low battery" symbol, which means my phone didn't exactly run out of battery yet. 

Why does this happen?

Additionally, how can this behaviour be overridden? (say in the event of an emergency and I need to use every last bit of the phone's power?)
Prowler answers your first question well: "Why does this happen" -> Prevents data corruption.

To answer your question "How can this behavior be overridden?"

You can try:

setprop status.battery.level 50 from a shell terminal.

Note that bypassing the shutdown is 10x more risky than a battery pull. However, in a true emergency, benefit > risk.

Why it's more risky:

Battery pull = power loss to logic board, only unsaved data or partial writes / data-locks can cause corruption.

Dry-discharging battery = undervolting entire logic board, 3.0 volts instead of 3.7 volts can be like running your car on 8.5 volts instead of 12: Canbus stops responding, voltage leaks into serial connections, capacitors explode, etc. The same can happen inside your phone, except it's that RAM doesn't hold its correct value, processor misinterprets, accidentally writes the wrong NAND cells, etc, more so after hooking the phone w/ trashed battery up to a charger. The voltage difference between live power and undervolt battery can cause the same leakage onto the I2C bus. (Ever use a car charger with aux cord hooked up to the stereo... The alternator feedback is considered a "safe" amount of leakage onto the I2C bus.)