More than likely, your PC is not fully protected by any type of Internet Security software. There are a few ways to have your CD-Key stolen though.
1. You bought the CD-Key from a shady retailer.
2. You have viruses, trojans or malware on your PC and your key was stolen that way.
3. You got the game from a friend, or so-called friend, and then you played the game not knowing where it might have came from.
4. Someone came to your place and played the game and copied the CD-Key off the jewel case and took it home and used it for themselves to cheat with or hand out to other websites.
You never know. But, it all depends on the end-user, which is YOU!
You MUST keep your key safe and out of other peoples' hands.
You MUST not buy from a shady place.
You MUST get a very good Internet Security Program and have it installed and updated daily.
You MUST NOT let others play on your PC.