That is because it ain't about horsepower, it is about torque.
Horsepower (to make it simple) is defined as torque times engine RPM times a conversion factor constant. Since diesels typically do not turn over anyplace as close to as fast as gassers, the torque you'll get out of a given horsepower diesel is going to be greater than what you'll get out of a gasser of the same horsepower. To see how this works, imagine an engine that puts out 100 ft lbs of torque. A gasser might do this at 6,000 rpm, and a diesel might do this at 3,000 rpm. Both will get you up a hill in the same time, but the diesel is going to be rated at 1/2 the horsepower of the gasser.
To be sure, there are other factors in there, as pointed out above, but they START from here, and each of those others is smaller in effect than this.