This question already has an answer here:
If I want to shut down my machine programmatically or on the terminal, I must do
sudo poweroff or
sudo shutdown. If I want to shut down my machine through my window manager and desktop environment, I navigate to my application menu and click "shut down". This does not require my password. How is this implemented?