A couple of things to try, which have helped on Xperia XZ1 Compact;
Follow the steps described in this post :
If you ever do get problems flashing, particularly if the device boot loops, (i.e. either stops at the /e/ boot animation, or reboots back to recovery), then the following sequence has always got me out of trouble:
(in TWRP) Wipe system, cache and Dalvik partitions
Format data partition
Flash the new ROM (or the old one if you’re trying to get back a working version)
Boot the device, and complete First Time Setup app: you can skip setting up WiFi, mobile data, and your /e/ account, but do set any screen locks that were in place when the device was last working and backed up.
Back to TWRP, and restore the backup from the working device.
Reboot the system, and check the major functionality works (Calls, texts, mobile data, wifi).
If any apps keep stopping, try clearing their storage. If that doesn’t work, uninstall and reinstall the app)
If that doesn’t do the trick, maybe format the system partition too
Last resort: when I was testing my custom L4M builds, I got into a state where neither the ROM not TWRP would boot. Eventually, after much swearing, I resolved it be reinstalling stock ROM: see here for details
https://codeberg.org/petefoths-projects/unofficial-l4m-builds/issues/28#issuecomment-616961
If none of that works, then I’m fresh out of ideas