First, make sure the device is running Android 6 or higher.
If the device requests the previously registered account, you will need to log in with that account, complete the setup, and then remove it in the system settings. This will disable Factory Reset Protection (FRP), allowing the code to be used normally.