In Ubuntu you can hibernate your PC by using the following command:
sudo systemctl hibernate
The problem is it does not automatically lock the screen. To lock the screen use:
xdg-screensaver lock
Now we can combine it together:
xdg-screensaver lock && systemctl hibernate
Note that you will need to enable your user to execute systemctl hibernate without sudo. You can do it by editing /etc/sudoers. Just add:
your-username ALL= NOPASSWD: /usr/bin/systemctl hibernate