Why is pitch measured with respect to the horizon and not the ground?
Pitch is measured with respect to a plane orthogonal to the local weight¹ force, which is properly called the horizontal.

That is used because:


It is equipotential plane of the gravitational field. Moving around it won't change your potential energy.
Is always well defined.
Is smooth and locally flat (it is still a spherical surface globally, of course).
Can be measured by averaging inertial forces on board without external reference.


It is called simply horizon, presumably because looking at the horizon is the easiest way to find that plane by human senses.

Using ground, which is not flat, as reference wouldn't work. Aircraft need to fly mostly along the equipotential plane, because climbing to a higher one requires adding more energy by the engines and descending below means the aircraft accelerates and needs to dissipate (= waste) the energy. So following terrain would require quite a bit more energy than flying horizontal. Plus it would be very complicated.



¹ By weight I mean the sum of gravity and centrifugal force in the reference frame rotating with Earth.