Is it necessary to have an unlocked bootloader to root a device? My LG Stylo 2 Sprint Version running on Android 7 Nougat has a locked bootloader. LG made sure that the bootloader can't be unlocked.
This article states that it's possible to root with a locked bootloader.

When the boot loader is locked, and the manufacturer doesn’t provide a legitimate method to unlock it, you usually need to find a flaw in the device that will serve as an entry point for rooting it.
First you need to identify which type of boot loader lock you have; it can vary depending on the manufacturer, carrier, device variant, or software version within the same device. Sometimes, fastboot access is forbidden but you can still flash using the manufacturer’s proprietary flashing protocol, such as Motorola SBF or Samsung ODIN. Sometimes signature checks on the same device are enforced differently when using fastboot instead of the manufacturer’s proprietary download mode. Signature checking can happen at boot time, at flashing time, or both.
Some locked boot loaders only enforce signature verification on selected partitions; a typical example is having locked boot and recovery partitions. In this case booting a custom kernel or a modified recovery image is not allowed, but you can still modify the system partition. In this scenario, you can perform rooting by editing the system partition of a stock image as described in the “Rooting with an Unlocked Boot Loader” section.
On some devices, where the boot partition is locked and booting a custom kernel is forbidden, it is possible to flash a custom boot image in the recovery partition and boot the system with the custom kernel by booting in recovery mode when powering on the phone. In this case, it is possible to get root access through adb shell by modifying the default.prop file of the custom boot image initrd, as you’ll see in the “Abusing adbd to Get Root” section. On some devices, the stock recovery image allows applying updates signed with the default Android test key. This key is a generic key for packages that do not otherwise specify a key. It is included in the build/target/product/security directory in the AOSP source tree. You can root by applying a custom update package containing the su binary. It is unknown whether the manufacturer has left this on purpose or not, but this is known to work on some Samsung devices with Android 4.0 and stock recovery 3e.
In the worst-case scenario, boot loader restrictions won’t allow you to boot with a partition that fails signature verification. In this case, you have to use other techniques to achieve root access.

This seems counterintuitive, but is it necessary to have an unlocked bootloader to root a device? Otherwise, do any of the methods mentioned in the article work?
No, it's not necessary to unlock bootloader for rooting. But flashing custom ROM or recovery is not possible without unlocking the bootloader because locked bootloader verify the ROM or recovery being flashed for company's official signature and custom ROM doesn't contain the official signature. So you cannot install a ROM or recovery of your choice on your device.
And also on some devices, you have to install a custom recovery for installing SU binary which is needed to get root access. In that case, you can't even get root access without unlocking the bootloader.

As per XDAForums,


  In case of nougat, You have to flash some custom recovery for your
  device and flash SuperSU using it.


And you have to flash custom recovery TWRP which will only be done by unlocking the bootloader as you can root without unlocking the bootloader (only in the case of direct root if available) but you can't flash recovery without unlocking the bootloader.

So the only option you have now is to unlock the bootloader. If you really want to root, make a full backup of the phone through software like MobileGo and proceed. Why hesitating?

You can read more here or here.