I'm scanning a Code 39 barcode. Why are some characters swapped (e.g. Y and Z)?

Most likely your scanner is connected to the computer via USB or via a keyboard wedge, a Y-shaped cable that connects the scanner, the keyboard and the PC. Per default most scanners are set to emulate a US keyboard layout. If your original keyboard, however, has a german keyboard layout (to pick an example) the letters Y and Z are swapped compared to a US layout, resulting in this behaviour.

Your scanner's configuration manual will have a section named "Keyboard layout" or "Keyboard language" or something like this. This section should provide information on how to configure your scanner so that it matches your keyboard.