sudo vim /etc/systemd/system/xscreensaver.serviceContent of the file:
[Unit] Description=Lock X session using xscreensaver Before=sleep.target [Service] User=ptacnikt Type=oneshot Environment=DISPLAY=:0 ExecStart=/usr/bin/xscreensaver-command -lock [Install] WantedBy=sleep.target
systemctl enable xscreensaver.service
Try to close and open the lid.