Where does the potential energy of capillary action come from?
Where does this potential energy of capillary action come from, or is this an exception or something?


First, the laws of thermodynamics still apply. Second, you have to account for the energy balance when you go from dry to wet on the one hand, and continuous flow on the other hand.


Initial wetting of the paper towel or glass tube: Quoting from one of the comments, "the increase in gravitational potential energy is countered by a reduction in the chemical potential of the substances due to a change in the areas of mutual contact". That explains why the capillary fills up in the first place, and in this case it is fine to say "water pulls itself up".
Continuous flow. If you are asking about a tree, where there is continual flow, you are not increasing the water-capillary contact area anymore, it remains constant. The energy has to come from somewhere else.
It takes some energy to remove a water molecule from the top of the
capillary because as you do, you are pulling all the water molecules
up a tiny bit. As explained in the excellent video by Veritasium, water can have negative pressure in the capillary, so trees can grow higher than atmospheric pressure might suggest (thanks, A.K., for the pointer to the video). This is not a problem for the tree because the top of
the tree is the site of photosynthesis, so there is free energy
available to do the "pulling". So you can think of the water-filled
capillary serving both in the role of the rope and the bucket, if
you compare it to fetching water from a deep well. In cases where the water simply evaporates, the energy comes from cooling down the surrounding as the water molecule pulls up another water molecule and evaporates. In the case of continuous flow, water does not "pull itself up", something on the top (or bottom) has to provide the energy. For example, if you put a towel in a bucket of water with the towel reaching over the rim a bit, the towel will get wet. However, if the end of the towel outside of the bucket reaches below the water level, it will continuously siphon water out of the bucket, with water dripping from the towel.


As an aside, it does not take much work to lift a water molecule up a tree (1.8 J/mol for a 10 m tree). Hydrolysis of a single ATP affords about 50 kJ/mol under physiological conditions, so it is sufficient to get 25,000 water molecules up the tree.Gravity is weak compared to electromagnetic interactions, which dominate in chemistry.