There is a helper app built into Android (at least up to 12) called locksettings. It's located in /system/bin/
On my rooted device "locksettings set-pin xxxx" where xxxx is the new pin, sets a new pin. "locksettings clear --old xxxx" where xxx is the current pin, removes the pin and effectively makes it so there is no lock.
Exchange "set-pin" with "set-password" or "set-pattern" depending on your lock method.
For pattern lock you need to translate the pattern to numbers. Top-left is number 1, top right is 3, middle left is 4, middle right is 6, bottom left is 7 and last dot is number 9