A key code can only be used once, so a code that's already been registered won't activate again — that's the whole reason a second attempt fails.
If you've lost yours, the code is usually printed on the manual or on a sticker on the case for a physical copy, and it's often stored in your account or order history if you bought it digitally from Steam.
Buying a second-hand disc without a code is the common trap here: if the previous owner registered it, you're stuck, and no amount of retrying changes that.