Critical hits—or "crits"—in Team Fortress 2 are largely handed out at random, but a few factors can influence them.
As a Sniper, landing headshots is one reliable way to deal extra damage. Certain weapons are also designed with a higher or lower chance to score a crit. On top of that, the Sandvich can grant a temporary boost that increases your crit chance, and it drops randomly during play.
So while you can't fully control crits, smart weapon choice and a well-timed Sandvich can tilt the odds in your favor.