Since Android 5.0 there is a feature called 'Smart Lock', which allows you to access your device without entering your password, pin or pattern.
It is possible to lock the device via
shell by emulating a power button press:
adb shell input keyevent 26
Once on the lockscreen, Smart Lock can be temporarily stopped by holding down on the unlock icon (see question) ↓
How can the device be locked and require a manual unlock using a shell command (or script) with or without root access?