Let's quantitatively examine the data: level 3 sentry guns top out at 216 health. Most stock melee weapons (minus the Scout and Spy) do 65 damage per hit and, while other melee weapons may also do 65, no other melee weapon does more unmodified.
So, four hits with most unmodified melee weapons will do the trick. This can take some time so I defer to Powerlord's answer in this case: circle-strafe your heart out.
Of course, there's the problem of getting to the sentry before you have the opportunity to do your melee damage. If you can't find a way to distract the sentry in another direction, your best bet is to Just Go Fast. Since we've determined that the Scout (more specifically, Atomic Punch) is a sad excuse for doing lots of upfront melee damange, our choice falls on the Demoman's Chargin' Targe.
Using the charge functionality, the Demoman moves roughly 2.63 times faster (750 HU/sec) than his base (93%) speed. That's a lot less time you're being shot at.
All those things I said about melee weapons not doing more than 65 damage don't really apply for the Demoman. Sorry, I lied. The Scotsman's skullcutter does 78 damage and it has an enhanced range (at the expense 15% speed, but that doesn't matter - we're using the charge).
So, you charge the sentry and one of three things happen:
- you deploy a non-full charge (no direct damage + minicrits)
- you totally miss the sentry (or come up short) but finish a full charge (no direct damage + crits)
- you hit the sentry with the targe at the end of a full charge (50 damage + crits)
Case 1, minicrits: Your skullcutter does ~105 damage for a limited amount of time. Not quite enough damage to finish it with two hits. Probably not an effective plan.
Case 2, just crits: Your skullcutter does ~234 damage for a limited amount of time. One-hit kill on the level 3 sentry. Probably a very effective plan.
Case 3, 50 damage + crits: You get the idea... it's even less likely that the sentry will survive after 50 + 234 damage.
In the case that we're including the Ullapool Caber (like, if this is a suicide run), not much changes. The half-charge minicrit case does ~200 damage - a lot but not enough for a one-hit kill. Crits with the Caber do 300 so that's a good play if you don't care about living through it.
My suggestion is to NOT aim your charge directly at the sentry, but just next to it. If you can time your charge right, you can finish your charge slightly next to and behind a sentry (giving you precious seconds while it turns to fire) and then turn around to smash with your end-of-charge crit - again, a single crit skullcutter hit does more damage than a sentry can handle.
Surviving the trip to a level 3 sentry isn't easy either. With a 175 base health, you can survive a little more than a second being directly shot at by a level 3 sentry, so your chances increase by being overhealed.
Oh right, no crits on buildings. I still stand by the Targe, only this time I highly recommend charging behind the sentry and slamming it with the Caber.