This is Google's lovely FRP (Factory reset protection) system, pretty much not a good idea to reset an Android device if you forgot the lock screen passcode as it usually messes things up.
Rules for FRP to enable itself:
# Lockscreen passcode (LG KnockCode, PIN, Password)
# Google Account registered to device
As long as you remove lock screen passcode before a factory reset the phone will be fine but resetting the phone with a passcode will sometimes cause FRP to glitch and not register any of the email address used making the device a brick unless you can flash stock ROM back onto the device and I'm not entirely sure this will fix it.