The surface sand was very dry on the beach at Rosemarkie. Underneath was a layer of wetter sand that made good sandcastles. The dry sand made the pile on the right beyond the last decent sandcastle. So what does the water do? Even NASA have looked at this. It turns out that it is the surface tension of the water droplets that holds the grains together.
https://science.nasa.gov/science-news/science-at-nasa/2002/11jul_mgm#:~:text=Damp%20sand%20sticks%20together%20because,grain%2Dto%2Dgrain%20bridges.&text=Adding%20water%20to%20damp%20sand,sand%20can%20still%20puzzle%20researchers.