In the first case, this is the surface tension of water. Baidu Encyclopedia explains the surface tension in this way: the tension between any two adjacent parts of the liquid surface perpendicular to the dividing line of its unit length. The formation of surface tension is closely related to the special stress state of molecules in the liquid surface thin layer. The existence of surface tension forms a series of special phenomena that can be observed in daily life. For example, capillary phenomenon, soap bubble phenomenon, wetting and non-wetting phenomenon between liquid and solid in narrow tubes with small cross section, etc.
In the second case, because air can't get into the glass, water can't get in (and the water inside can't flow out). Similarly, if you seal the quilt with a piece of paper and turn it upside down, no water will flow out. For the same reason, there is no air inflow.