I was wondering if root is required or only unlocking the bootloader will do for custom ROM installations?
I already have TWRP installed.
In almost all cases: No.
Flashing a custom ROM is done in the recovery.
The recovery is independent from the system (which you can root) and thus no online/active system protection is present.
Sometimes you need to unlock the bootloader in order to write to the system partition at all (comparable to hardware write protection).
This can often be done in
fastboot oem unlock).
Many custom ROMs will provide root access (for developers of the ROM, no custom ROM is/will be in a production-ready state).
Thus flashing a custom ROM is way to gain root access.
For the cases where it won't work (weirdly locked bootloader), you need a rooted device to unlock the bootloader from within the running system (because of signatures, for instance).