How to counter Pyro as a Scout?

You don"t need to avoid contact. In my experience an experienced scout can more often than not defeat an experienced pyro.

The best "tool" that a Scout has to use to his advantage is his movement speed.

Under most circumstances, the Scout can move faster than the Pyro, and the scattergun can be used right outside the Pyro's attack range, so as long as you remain moving you are harder to hit therefore harder to take damage. Obviously you cannot get too close as the Pyro is a very good DPS class at close range, so just stay close without being too close.

Your pistol can also play a vital role, allowing you to pepper the Pyro with a few shots at medium range, which the Pyro is very weak at.

Some unlocks that can help aid you include the Sun-on-a-Stick with its fire resistance should you catch on fire and need to temporarily retreat, the Mad Milk can be used for extinguishing yourself, or perhaps even the Force-a-Nature with its knockback ability keeping the Pyro away from you.