WhatsApp Web includes a screen lock feature that automatically locks your screen after a certain period of inactivity and would need a password to get you back into WhatsApp.
Here is how to configure it:
Login to WhatsApp Web and click on the menu icon. Then choose Settings.
Click on Privacy.
From there, scroll down to the Screen lock option.
By default, this is disabled. Click on it. It would then require setting a device password.
This screen lock password would be local to the PC you are using WhatsApp on.
After setting a screen lock password, you can change the period of inactivity after which the screen lock would be active.
By default, it is set after 15 minutes, but you can change it from the available choices if needed.
From now on, whenever you are not using WhatsApp Web and the inactivity limit is crossed, you will need that password to get back in.
Also, as this is a local password, and if you happen to forget it, you can remove it by unlinking your current WhatsApp Web session from the phone and set up a new one again from your phone to the PC.