It’s a combination of frame design, wheels and tyres, gearing, weight and rider fitness.
We all know that a road bike is faster but even a change of wheels makes a difference – mine came with some bog standard Shimano wheels but fitting a pair of Mavic Ksyrium SLs, which are very stiff, light wheels has made climbing more efficient. Dunno about speed but climbing certainly feels easier.
My chainset is a compact, my lowest gear is a 34/27, quite a lot faster up a hill than my MTB with something like 24/32.
Since taking up road riding (after 22 years of mountain biking) my weight has dropped from 75 to 70 kilos, which makes a huge difference on hills.
My resting heart rate has dropped from 52 to 48. I am certainly faster on the mountain bike now.
On the road bike a short hill doesn’t seem very significant; you simply blast up it losing as little momentum as possible whereas on the MTB you lose that speed very soon, drop to middle or granny ring, sit back and plod up the hill. On long steep hills getting out of the saddle takes you a lot further per pedal stroke than on the MTB, which feels so heavy and ponderous that you might as well be dragging an old car tyre behind you.