This is because bikes cost you about 50% more energy going uphill than walking[1]. You get back everything you don't lose from having to pedal too slowly, hunch over the front wheel, and maintain constant torque on the pedals.

1: https://pedalchile.com/blog/uphill