I pretty much solely play sniper (back when we still had warpath, sigh), and one of the first things I found necessary to do was to decrease the mouse sensitivity. Other people here definitely have the right idea about that. Generally, if you want to snipe, try to keep it somewhere low (I personally use 1.8), but really, do whatever feels right to you after some practice with it.
My second piece of advice regarding close range sniping is this:
Oftentimes when an enemy is rushing you (a pyro for example) and they see that you're zoomed in, they'll instinctively serpentine (i.e. running forward while swerving right and left). Basically, such a back and forth tactic makes their movements extremely predictable. If you center your crosshair and build the charge, you can easily catch them as they move to the other side. Basically, let them run into your crosshair for you. That being said, this works best on classes like the pyro, engi, or medic, who lack a powerful long-range alternative.
For more long range classes like soldier or demo, I find that when they charge me at close range, they don't necessarily serpentine (demos sometimes do) but rather jump up and down and fire as they approach you. Again, this attempt at dodging is also extremely predictable, allowing you to catch them as they bob up and down (while you yourself need to be strafing left and right to avoid incoming shots).
Regarding the scout, I honestly have some of the easiest time headshotting them as they charge me. Basically, the scout moves so quickly and so much, that nearly half the time they jump into the shot themselves. The other half, I generally catch them as they reach the slow point on their descending arc from their double jump.
So basically, my best piece of advice for you is to understand enemy movement and predictability. Everyone thinks that their being unique when they charge you and try to dodge. Truth is though, they're making it quite easy.