I was having the same issue with Linage 16 and it exists with Linage 17.1
now its resolved for me and this is how: "Discovered Accidentally"
1- I Flashed Original Hydrogen OS I think Android 5.X.X "By mistake"
2- Flashed TWRP recovery V 3.0.0-0
3- Flashed BLUpdater zip to update bootloader and latest TWRP
"And here what I did to escape from Bootloop ghost that keeps chasing me with Linage 17.1"
4- Flashed Linage 17.1 and reboot "I didn't tick the option to install TWRP app as system app... so ignored"
5- Flashed nano gapps
6- I didn't flash magisk " It did bootloops for me before... but I am going to try it later"
7- Now everything works fine for me at least for the past few hours
Hope it will help some of you...