short: the usb stick has data on it that tells your computer what it is. this data gets sent over the usb port to the computer & the computer interprets it. so every device that you can plug over usb into your PC can in theory act as any usb device like a usb mouse, keyboard, flashdrive, webcam.. etc.
a lot of chinese scam usb sticks just override the data on the chip that tells the computer how big the stick is. but there are also stick that act malicious by acting like a mouse and keyboard & then opening notepad, putting malicious code into it, saving it, and then running the whole thing.. all by acting like a usb mouse and keyboard.