Though more Android smartphones are coming with unlocked bootloaders now than ever before, most of them still come with locked bootloaders, meaning you are unable to install custom firmware out of the box.
fastboot oem unlock is the Fastboot command you enter into the command line on a Windows computer that will unlock the bootloader on your smartphone. The same command will also wipe all data at the same time, so you must back up your device before running the command.
You only unlock the bootloader when you want to install a custom recovery image or custom firmware (also known as a custom ROM). Unlocking the bootloader isn’t always a requirement for getting root access to the Android operating system, though some rooting tools will unlock the bootloader during the rooting process. For instance, CF-Auto-Root is a popular one-click rooting tool for Samsung smartphones that unlocks the bootloader for you.
You never want to unlock the bootloader on Android unless you have to. As soon as you unlock the bootloader, the device’s warranty will be void. You don’t need to do any preparation on your device before you send it to a service center; let the manufacturer do what they need to do to the device. If you have unlocked the bootloader, the manufacturer will know when you send it to them because it will have tripped a token in the smartphone. And if they see the token tripped, they often won’t work on it. It’s also not true that a manufacturer would ever need to unlock a bootloader to troubleshoot a smartphone. As mentioned, the locked bootloader simply means you cannot install custom firmware, and the manufacturer doesn’t ever want to install custom firmware anyway. They might help you reinstall official firmware but never custom firmware.