PC games use key codes as a form of copy protection. Each code is tied to a legitimate, original copy of the game, which helps verify that the user actually owns an authentic version.
Since pirated copies typically lack the original packaging and a valid key, requiring a code makes it harder to install and run unauthorized copies. It's a simple but effective way for publishers to protect their products.