Why do we take $h$ as "height from surface to bottom" when calculating liquid pressure? In the following image, pressures of points x, y and z are $P_{x}, P_{y}$ and $P_{z}$ respectively, and they all are equal. My question is, why?
The amount of matter on x is much more than amount of matter on y. Why do they still have equal pressure on them?

 A: A simple though experiment is to fill all the space up to the surface by water and remove the walls. Now you can easily believe the formula $p = \rho g z$ (as the same amount of water rests on the points x, y and z) and the water is static as all forces cancel. If you now insert the (infinitesimally thin, totally rigid) walls, the forces acting on them exactly cancel out – the pressures obviously do not change. If you now remove the water surrounding the walls the pressures inside the tank will not change either (how should they), this means that the walls now supply the force, that the water outside supplied before, otherwise they would not remain in their position. This tells you that $p = \rho g h$ holds even in such containers as sketched in the question.

More formally: Because the condition for a fluid to be static is $\nabla p = \vec f$, where $\vec f$ are the external force densities.
This can be derived by considering a small box of fluid with sides of length $l$. For the small box  of fluid to remain static, the forces acting on it have to cancel. The pressure on the sides of the box exerts forces like (in the $x$-direction, $p_1$ is the pressure on the right, $p_2$ is the pressure on the left):
$$ F = A (p_1 - p_2) = l^2 (p_1 - p_2). $$
So in the limit of a small box this gives:
$$ F = l^3 \frac{p_1 - p_2}{l} = V \frac{p_1 - p_2}{l}. $$
So the force density in the x-direction is
$$ f = \frac{p_1 - p_2}{l} $$
For $l \to 0$ this goes to the derivative $\partial_x p$. The same arguments apply in the y- and z-directions.
For a constant external force $\vec f = -\rho g \vec e_z$, like gravity, you can easily solve the equation (under the assumption that the fixed boundaries simply resits the pressure and that the pressure at the surface is imposed by the atmosphere above). You get:
$$ p = -\rho g z + p(0). $$
(Note that the variable $z$ increases upwards).
A: Weight is a downward-directed force; if the question were about weight, there might be differences in the X, Y, Z positions.  But, the question is about pressure, which is without direction; pressure is the work required, per unit of volume, to displace the liquid (like making a bubble).
Regardless of position, an injected void in the given scenario will
raise the top level of the liquid, by the same amount, and require the same
amount of work.  Imagine poking a cork down to the X position: that takes
some downward force, over a distance d.  That force times distance is the work required.
Now move the cork from X, to Y, to Z.   That takes no additional work
(because no sideways force is required to do the move).
