This behavior happens when one of the joystick's microswitches is permanently "pushed down". It's hard to say why this would be happening on a joystick, but generally it's the result of a bad cable (often this can be seen by inspecting the cable and fixed), or the underside of the joystick having something out of place (also visible and fixable). Worst case, you'll need to replace the joystick and it's cable, maybe the controller board.
Remove the button panel: https://polycade.com/pages/helphq-2#/collection/2975/article/13006
Then flip it over and unscrew the bottom enclosure (4 screws with silver washers around them).
Inspect the faulty joystick and it's cable. Compare to the working one. If nothing looks off, unplug joystick cable and plug back in. If still not working, replace the joystick (Sanwa JLF-TP-8YT).