As a Scout, you aren't supposed to deal with sentries. Each class has it's counters, and the Scout's high speed and mobility are easily countered by the computer-controlled Sentry.
The best way to get around sentries is to drink Bonk! Atomic Punch while your team is distracting the sentry.
However, if you absolutely need to take down a sentry, you will need to take advantage of the fact that sentries take full damage from weapons. Your pistol can take down a sentry, but only if the Engineer is not repairing it.
Additionally, many maps have alternate routes you can take. For instance, on the third stage of Dustbowl, there is a tunnel you can take to get behind any sentry guns.
So it is really difficult to take out sentries as a scout. Try alerting your team to its presence, or switch to spy/soldier/demo and take it out yourself.