I had this problem with my iPhone 11 pro. I had forgotten the passcode and wanted to do a complete reinstall.
I booted the phone in recovery mode, would get the screen, showing the laptop with a cable. When initiating the recovery on my macbook, it would reboot (within a minute) and would exit recovery mode.
The suggestion of first downloading the IPSW also didn't work for me, as while extracting the package, it would already reboot.. very frustrating.
Eventually I figured there's a difference between 'recovery mode' and 'DFU mode'. In recovery mode, it shows the laptop and cable, but in DFU mode, the phone starts without the use of iOS and shows a black screen.
Once I discovered this and connected it to my laptop, I was able to reinstall it without an issue (from DFU mode it didn't restart automatically).
I hope this may be the solution for some others facing this issue as well :)