As Marcus above states, it is the capillary action between the close-fitting pipe and fitting joint. When molten, the solder flows very nicely TOWARDS the heat, so that is why one heats the joint to be soldered, and then apply the solder from the outside. You know you are at the right temp when the solder melts smoothly from the stick and flows cleanly along the flux edge. The flux is to to keep the surface oxide clear while heated, since metals oxidize easiest when heated. But it is a combination of exactly where the heat in the joint is and the capillary effect. When molten you can pull the solder along by heating where you want it to go, it will flow towards the heat.
As a US Navy Welder, this is something I had to be GOOD at, and not just tin/lead solders, but high grade .30 and.50 grade silver solders for high pressure steam and air lines. Is actually closer to brazing than soldering, but it is a matter of the use and different temps. Tin/lead is such a low melt point compared to even a soft silver solder, but they still work the same way in how they 'wet' and flow along the surface and into the joint being soldered.
I could bring a clean meniscus to both the outside and inside surfaces of the solder joint. This was one of the tests, along with pulling a 1/4 oz of grade 3 silver solder through 6 feet of 1/2 inch thin walled copper pipe. Lots of prep, knowing what you are doing with the equipment and a knowledge of physics made a big difference in my training time. I was top of my class with Welding/Hull Tech School.