I believe a diode would be connected to prevent USB5V from supplying current externally through the 5V pin.
On the other hand, since there is no diode on the USB side, if a voltage higher than 5V is supplied from outside, current may flow into the USB side (PC side).
Whether USB 5V or external 5V is supplied, it will be converted to 3.3V by the on-board voltage regulator, so I do not see how this is related to the code not working.