No 8 year old poos their pants just for the hell of it.. so there IS a problem whether it is physical, or psychological/behavioural. The GP sounds very unhelpful to be honest and I would go see a different doctor and ask to be referred to a paediatrician and take it from there.
Punishing him is NOT the right step.. nor is threatening him with nappies ..frankly I can't believe anyone thinks it's ok to suggest that.. it won't solve the issue and will be utterly humiliating for him. It's ok, assuming that he is capable, to ask him to clean himself up and maybe deal with the dirty pants (ie rinse them and put them in the washing machine) but it's NOT ok to smack him, threaten him or leave him in them.. that is just vile.
I'd start by ruling out the obvious.. does he have loose bowels/ or constipation which can cause overflow poos? Is he scared of using the toilet.. does he associate it with pain from previous hard poos, or does he just feel unable to go in public loos. Does he get too busy playing and leave it too late? Or does he feel the need for attention so that negative attention is what he responds to (I'm not saying this is the case but it happens more often that you would think!)
I work with children who have special needs and poos in the wrong place are something I deal with daily. Without exception there is always a REASON for the behaviour even if it is not apparent and rather than getting angry it really helps to try and work through the reasons.
Also.. given that there IS a problem.. what have you done so far to address the problem? Is there a reward system in place.. a day with no poo-ed pants = a star on a reward chart. 7 stars = new toy/ sweets/cinema.. whatever WORKS for your son. It makes no odds whether you think 'well I shouldn't have to do star charts cos he's too old to be poo-ing his pants' he IS so you need to get creative.
Apologies if you are already doing these things but the fact that you are hitting your child makes me think that you may need to step back and think about positive steps to help him. However he may APPEAR I doubt very much that he doesn't care..