Easy way to upload sketches using MIDI (without RX pin removed)
To allow the bootloader on the Arduino MCU to communicate with the USB chip, the TXD/RXD pins are connected:



These connections have 1 kΩ resistors so that the signals of the USB chip do not interfere with your own hardware too much. However, this means that your own hardware can easily override those signals.

In this case, your MIDI hardware actively drives the RXD line to a high level.

You is no way to work around this in software.
You could try to replace the optocoupler's pull-up resistor (270 Ω) with a 10 kΩ resistor, which would make the USB controller's signals ten times stronger than the MIDI ones, but this might make the signal edges too slow.
To reliably prevent conflicts, you have to add a disable function to the MIDI receiver, or power it down, or disconnect it.