As a Scout, you aren't supposed to deal with sentries. Each class has its 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. Rushing in without team support will cause the Sentry to push you away. Invulnerability does not protect you from knockback.
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 (no loss of damage from distance). Your pistol could take down a Sentry due to its accuracy, 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.