Charging is a complex task for mobile devices now. For example, power can come from either USB or a wireless charger. When USB was developed in the early 90's, it was designed for peripherals such as mice and keyboards - smartphone charging wasn't even on the radar (pagers were the hot thing back then). So USB charging is a mess of its own on the technical side.
What this means is that your phone's CPU and its firmware is involved in the charging process, and if the CPU is completely frozen, then the necessary communication between the phone and its USB chipset won't happen, and you could be in a situation where the charger won't work because the CPU isn't following the necessary steps.
The power button on a phone is a "soft switch" - it's software controlled, not a physical on-off button, and some part of the phone is always powered to respond to that button even when off (thus turning it on while charging should always be a non-issue). Computers have been like this since the early 90's - and if you couldn't turn it off because of a complete lockup (rare, but possible), you'd have to resort to unplugging it.
The equivalent of "unplugging" on a smartphone is removing the battery. Given the trend of non-removeable batteries, this isn't an easy option. But if the battery completely dies and runs out of power, it's the same thing.
You may try holding the power button down for 10 seconds and see if it will restart. If it's completely froze you have to wait until the battery runs completely out, or take the phone apart to unplug and replug the battery.
What can make a CPU completely freeze such that even holding power for 10 seconds won't reboot it?
- OS issue - make sure Android is at latest version.
- Bad charger/cord, try a different or new charger/cord.
- If using a custom or aftermarket ROM, check for a later version or revert back to stock firmware.
- Physical issue such as battery going bad, physical or liquid damage.