How I can prevent my android phone from getting rooted? Usually  people try to install a custom rom on a stolen android phone to erase all its data and identity.
Is there any way to prevent the thief from installing a custom rom or rooting it.
If a thief has physical access to your hardware, it's his.
You cannot prevent the thief from entering the bootloader or recovery and flashing your device.
What you can do is go to your local police department, tell them your phone has been stolen and you have the IMEI (it's on the box but note it down separately) and they should block any use of that IMEI.
No cellular connection will be possible with that device, it's merely a small tablet and all connection attempts will be logged with location of the cell tower, approximate location of the device and time.

After that, wipe your personal data using one of many different remote security solutions (like the Google Device Manager).

Also tell your cell provider that your phone has been stolen so you can get a new SIM (might need to pay for that) and to block any use of the old SIM card.

Also: Thieves usually just wipe the data and don't install a custom ROM (rooting is an option, though).