To the OP ....
I used to get this a lot when I started cycling again. I'd be out on my road bike, and fly past MTBs on the flat, only for them to casually pass me on the hills while I was red faced and gasping for air. I put it down to 2 things.
- They were fitter than me.
- Their MTBs were low geared, so they were spinning out on the flat, which is why I could pass them.
Since then, I've gained a lot of fitness and lost some weight, and I'm rarely passed by anyone on a MTB if I'm on the road bike, but there is some element of planning in it. If I'm catching up with someone who looks seriously fit on a MTB and I know there's a challenging hill coming up, I'll often slow down and play with the Garmin for a bit, and wait and see how quick he is on the hill. If it turns out he's slower than me, I can pass him on the hill and feel even better about myself!
My experience is that the majority of MTBers around here are stronger/fitter than the majority of roadies, probably because they do take their MTBs up mountains, and some of the off-road climbs make the road climbs a breeze by comparison. Just riding up into the mountains a few miles from us is a near death experience for me, but I know if I did it regularly, it would really help my road fitness.