If you do a clean flash and select a suitable TWRP to flash the ROM the chances of getting a bootloop is less.
Every Android custom ROM by version has a TWRP compatible for it. For example to Android 10 you need to have SAR (System As Root) enabled TWRP in most of the legacy phones which was launched with Android Oreo.
When you are installing Android 10 on a previously installed Android Pie you need to clean the data partition, system partition and the cache partition.
Cleaning of all the above partition(s) is known as clean flash. This is must if you are flashing a new Android verison on top of the older one.