If you flash the custom kernel boot.img or the stock boot.img it will remove root, the zip flashed through twrp should preserve both root and twrp if I remember correct. I had said that because you had specifically asked about the boot.img, I apologize for any confusion
Ahh! Too late. I just lost root and that's ok. I'm not worried. I'll reflash Magisk but is it safe to flash Magisk.zip instead of the patched boot.img? What I did was flash the custom kernel via fastboot then I flashed TWRP 3.6.2_11-0 by selecting "flash current TWRP" in TWRP. While I'm making a backup, my phone still restarts. Flashing TWRP didn't solve the issue. Is it because I didn't reflash Magisk yet or is it something else?
@Electimon
Could you tell me why I'm having the issue?
Update: Now I know why I'm having the issue. It's a data partition that causes the issue. I made a backup of other partitions except data and it went well. I'm gonna uninstall certain apps then make a backup of data again. I'm back. I uninstalled certain apps and the issue still persisted. I gave up, so I rescued my phone. I rooted it again by flashing Magisk 25.1.zip via TWRP and it went well. Thank you for trying to help me.