This is the result of a competition between the adhesive forces and the cohesive forces in the liquid.
The adhesive forces that attract the molecules of the liquid to the surface of the glass are greater than the cohesive forces that attract the liquid molecules to each other.
Since the adhesive forces are greater than the cohesive forces, the liquid rises up the tube until it is just balanced by the downward force of gravity on the liquid column.
Note that not all liquids will rise in a capillary column.
The cohesive forces in mercury are greater than the adhesive attractions for the glass.
So the column is depressed to a level at which the pressure of the mercury outside the column just balances the adhesive forces.