yes, I rooted my old phone to install custom ROM and save the recovery( my Chinese phone would remove custom recovery if I didn’t root
iirc, the process was miui->twrp+pixel exp.+magisk+format data then I had a rooted phone but I didn’t need the root so I flashed pixel exp. and did a format data again and magisk was gone
root should go away after clean flashing the ROM again as the update guides always say if you want to retain root, flash magisk after flashing ROM