Buy the game from store.steampowered.com.
Team Fortress 2 is distributed through Steam, and purchasing it there attaches the licence to your account directly — there is no separate product code to hunt for or keep safe. That is the practical advantage of the platform for this title: the "code" is your account.
Team Fortress 2 has been free-to-play for a long time now, so unless you are after something specific, you can simply install it from your Steam library at no cost. Be cautious of any site selling "TF2 product codes," since there is nothing legitimate for them to be selling.