If you read the readme file in the docs subdirectory, they already said KOTOR2 does not support joystick or gamepad.
However, if you really want to use a controller, there's an open-source project that can help you.
It is called "Auto Hotkey", here. It allows you to create a script file, then turn the script file into an EXE (optional), and run it before you start KOTOR2. The script will intercept all inputs (mouse, keyboard, controller), and you can re-arrange/alter/remap them as you like.
If you need more help on how to write the script file, ask here or ask in AutoHotkey's website.