That is made possible due to the default Factory Reset Protection (FRP) that Google places on Android phones from version 5.1 and above.
If you grant the permission, another person cannot just factory reset your Samsung Android phone and start using it as theirs.