How to stop Stock ROM overwriting the Custom Recovery? I was trying to flash a Custom Recovery (TWRP) on my Friend's phone (Realme 3).

It was officialy supported by TWRP and was listed on their website so I downloaded the Custom Recovery. Then I unlocked the bootloader of his phone but yes a strange thing happened there:

After it asked for pressing the volume button to be pressed it unlocked the bootloader – but after that there was option "Select boot type". It had three options: Boot to Bootloader, Boot to recovery and last Normal boot. Further there was a arrow on the bootloader option. And there were some instructions something like volume up for select and volume down to move.

But I tried every button but the arrow was stuck on the bootloader option. So I connected it to my device and used the "fastboot reboot" command to restart the device. After restarting at the realme logo it was saying "You are unlocked you cannot be trusted". But after that it booted normally and the phone was Factory Reset.

After this in the Developer options the OEM unlocking was grayed out saying Bootloader is unlocked. Ok so we were successful in unlocking the bootloader.

After that I pasted the twrp img file in the platform tools directory and put the command adb reboot bootloader and after the device was in bootloader I used the command fastboot flash recovery name.img to flash the recovery. It said sending and then writing in my terminal.

After that I used the command fastboot reboot and the the key combinations (power+volume down) for the device which used to get into recovery for that phone – but this time, instead of going into recovery, it was in the bootloader.

So again I tried fastboot reboot command and this pressing the power+volume up but the phone booted normally. So this time I tried adb reboot recovery – but it booted into stock recovery. So again I tried flashing the recovery and tried using fastboot reboot recovery but it didn't work.

And yes I know that after flashing the custom recovery the phone should first boot into the recovery but as I said neither the key combinations nor the fastboot reboot recovery command so what can I do to prevent the system from overwriting?
Ok I was able to install the TWRP Recovery using my device's stock recovery's install method... And it worked!!!!