I just came across the instructions to factory reset Apple device if one does not remember the device passcode: https://support.apple.com/en-us/HT204306
I am very new to Apple and I don't understand how come Apple allows such a thing. What if someone stole my device and wants to clean the device before selling it? Should the iTunes on the connected computer be logged in with the same Apple ID as the locked device? Is that what would prevent a thief from cleaning a stolen device? Would the above instructions work if the iCloud account on the device is locked as well?