Sharing IO pins – UART
You need the two UART pins available for programming use (if you’re not using the ESP32 USB interface) even if you want to use the JTAG interface (you need to fall back to the serial interface at times, its the default means of programming the ESP32). You can share them with other bits of your circuit just as long as you can still use them for programming as and when needed.
You will probably want them available for debug output via print() during development work too.
Sharing IO pins – JTAG
When you are using the pins for the JTAG your application must not drive them. There is no automatic taking over of the pins by the ESP32, when the application is programmed and run, if it turns the pins into outputs then the JTAG interface will be destroyed and you’ll need to re-program a new version without the pins used (or erase the program) via the UART interface to get the JTAG interface back.
Some ESP32 devices (e.g. ESP32S3) default to JTAG assignment of the IO pins via the IO matrix and the pins won’t work as genernal IO until you call gpio_reset_pin() – see here.