In order for a user on a remote computer to shut down another computer whether it's a Mac or a PC, they have to have access to it first.
Whether you are using screen sharing or doing this via terminal, regardless of the computer's state (locked or unlocked), if the user has access and the requisite privilege , they can log in and initiate a shutdown.
It's very important to recognize that to shutdown a Mac, you don't need another Mac. You can do it from Windows, FreeBSD, or Linux.
Using an SSH client (Terminal on a OS X) you would log into the remote machine with username/password and machine IP/DNS Name
If you have the appropriate credentials, you would issue the command
sudo shutdown -h now
You could issue these commands regardless if the system was locked or not, even if someone was logged in and working at the time.
By using another Mac and it's screen sharing capability or via VNC, you could easily connect to the remote screen, and shutdown the machine even from the lock screen (notice the bottom icons):