In addition to what already was stated, namely:
- ... how the CIA (Complex Interface Adapter) maps JoyStick - or in general, any - input:
The signals a (digital) JoyStick delivers, come in via Pins 1 to 4 (Up, Down, Left, Right) and additionally Pins 6 and 9 for the buttons (Left, Right) - the equivalent values are represented on the charmap by e.g.: SPACE for Pin 6 aka Fire|Click and other keys, like Numbers and Arrows (can't recall which exactly, i think LEFT-ARROW was one of them). - Signals are cached in CIA #DC01.
But for the second Port the keys representing its signals are always a key-combination starting with the C= | Cequal (as in equal and as in "Key is followed by another, so it becomes a sequel") | Commodore-Key | The Key with the Commodore-Logo. - Signals are cached in CIA +DC00.
Also, the yet not mentioned pins 5 and 9 cache the position (y- and x- -axis) for analogue joystick | mouse | paddle operation-mode.
While the pins used for digital signal input are generic as in cross-platform on (purposely) identical ports like e.g. on Atari ST or Amiga, the analogue ones are not.
But regarding your question, another detail has to be mentioned:
The CIA has at an offset +2 to the direct digital signal cache registers - so for #DC00 at #DC02 and for #DC01 at #DC03 respectively - registers that state if a signal is read-only or if it is allowed to write to it.
Furthermore, the C=64 is designed to allow for a charmap-flip from alphanumeric with UPPER- and lower- -case to UPPERCASE plus GRAPHIC-SYMBOLS.
Another factor can be that a game makes use of memory-intensive bitmap-graphics and therefore has to swap-out some memory from kernel-space (Yes: KERNAL, it's okay, calm down ...), which leads to an overlap with the registers for the Joystick.
Or the game makes intense use of (especially ring-)modulation for its sound-processing, which in return contaminates the registers for the Joystick-ports, because the processing of analogue JoyStick|Mouse|etc. is handled by the SID sound-chip. It is kind of hardwired to the registers for x- and y- -axis in the #DC00|#DC01 and making use of it switches these to read-only mode. So input can not be processed simultaneosly.
Maybe the game syncs graphical representations in general and RasterBars | Z-Scrolling | interlaced colors | etc. specifically to IRQs. This can affect the handling of the registers, too; mostly due to timing- and memory-swapping- -constraints.
Maybe the software has AI built-in or simplified NPCs (Non-Playable-Characters) to provide a single-player-mode for a game that actually requires two players to be playing; like TicTacToe, Chess, etc. - In this case it would be dumb to pollute the already very limited amount of RAM for the program with a stack of extra-routines solely for that specific case; Instead the computer-players simulated interaction is using the real registers of Port 1. This can be done even in basic, by using the equivalent Characters or KeyCodes of these or by poking directly into them. For that to work the registers have to be made writable. You can cheat in these games, by having a joystick in port 1 and overwrite the actions of the computer-player.
Using Port 2 for the human player mostly avoids many of the problems that can arise when the software is making use of the aforementioned methods. Why exactly, can't hardly be fitted in here and would be a separate task - or question - in this case.
Hope it helps. Anyhow. Thanks for reading.