My phone is rooted with magisk with android 9. I haven't got a custom ROM or anything. I done a factory reset and when when I try to complete the setup it crashes and says the android setup has stopped working.
Only thing I have tried is a hard reset but that didn't change anything
It won't allow you to reset the device if it is rooted. You would have to unroot it first. Then you would be able to do a reset.
I know of two apps that should be able to help with unrooting a device. Others may know of more or other ways, as I am really not a fan of rooting, so not my expertise. The two apps, which should be able to be found at the Google Play Store are "SuperSU" and "ES File Explorer". I think "SuperSU" is free but I don't know about "ES File Explorer".
How to unroot Android: Using SuperSU
Download, from the Google Play Store, and install "SuperSU".
Launch the app and go to “Settings”.
Scroll down and locate, and tap, “Full unroot”.
It will ask you to confirm that you really want to unroot your device. To start, tap continue.
When it is done, the app will automatically close and then restart your device.
When it is done, and the device restarts, it should be fully unrooted.
Uninstall "SuperSU" and you are done.
How to unroot Android: Using ES File Explorer
Download, from the Google Play Store, and install "ES File Explorer".
Launch the app and tap "Menu".
Scroll to locate “Tools”. Tap that and then turn on “Root Explorer”.
Now you will have to grant it "root privileges", if prompted.
Go back to your home screen and then navigate to your device’s root folder. It should found as “/” in explorer.
From root, navigate to “system” and then “bin”.
Find, and delete, the “busybox” and “su”. If you can’t find them, move on to step eight.
Navigate back to “/” and open the “app” folder.
Restart your Android device. Your device should reboot unrooted.