When you set up your phone, sign in with your Microsoft account and accept the recommended settings. If you don't turn it on during setup, go to Settings > Find my phone,and turn on Reset Protection.
To turn off Reset Protection, go to Settings > Find my phone,and turn off Reset Protection.