To shutdown your Raspberry Pi even when it’s crashed or frozen, you must have
- ssh enabled, and
- access to another computer on the same network (you can even use your smartphone.)
Do the following command:
sudo shutdown -h now
You can’t use
shutdown unless you have sudo privileges.
-h means halt the system
now means do it straight away.
Source: How to shutdown your Raspberry Pi