The debugger is not using a UART it is communicating via SWD with the device.
It only happens that the Nucleo boards have one UART connected to a virtual USB to COM bridge integrated into the debug header of the board (the part you can break off).
There are solder bridges and jumpers on the Nucleo boards which allow you to disconnect the UART from the virtual USB COM port on the debug header and route them to the normal pins on the headers.
The documentation and schematics of the Nucleo boards will tell you which solder bridges or jumpers have to be adjusted.