There are a few ways to know:
Firstly, the game usually have a CDKEY/license key. You need to enter this during installation. Some games do not have this. That is fine.
But pirated games usually have a CRACK code to "copy onto the installed folder". This is a telling sign the game is pirated. The keywords to look for are CRACK and also the main game's EXE file.
Next, most games requires you to place the original CD onto the CDROM drive to play the game. Even if you've installed the whole game. This is to (sort of) prevent buyers from installing on many computers. Eventually it is annoying to keep popping in the original CD onto 2 or 3 computers. This is quite a major headache for genuine buyers who paid for the license legal game. While the developers argue it's a safety measure. Gamers feel it restricts their gaming experience.
Lastly: newer games have "online authentication" capabilities. Or online activation. Basically the CDs that come with the game is not really essential. The main factor is the license, and user account. Think for instance, you have a bank account with Swiss Bank. Even if someone stole the bank book, you are still the valid owner because your telephone number is registered to the account. Likewise, the gaming account is registered to your email - and obviously only you have access to the email account. Games like Counter Strike Source, Half Life 2 - uses this system. Also new online multiplayer - massive online multiplayer games like World of Warcraft, Guild Wars, employ the same system. You can "steal someone's installation CDs" but you cannot gain access to play the game.
In the near future, PC games - and in the broader sense - computer software will be distributed on this basis.