The rating of a gearbox is determined by several design factors - the type and quality of the gears (material, hardness, precision, finish), the quality and precision of the roller or ball bearings (size, fit tolerance), the strength of the gearbox housing and the accuracy of the setup of the internals. Sometimes a box rated at 65 hp but with high-end design and components can actually weigh about the same as a box rated at 40 hp with lower-grade parts.
Gearbox horsepower ratings are based on "mean-time-to-failure" analysis that accounts for the load and speed that a given machine will stand on average before it statisticallyy becomes likely to fail. On the same tractor in the same use, an agricultural gearbox rated at 65 hp can be expected to hold up longer than one rated for 40 hp.