Overview
I'll avoid depending upon algebra as an explanation. (Because algebra, while providing quantitative answers, doesn't often help people understand something unless they are very fluent with mathematics.) Regardless, it's still helpful to have the datasheet available. So here is TI's LM317 datasheet just to make it convenient when needed.
The best way to understand something is to try and put yourself inside the device and "think like it does." Empathize with the device, so to speak. Then a lot of mystery goes away.
In programming, for example, there's nothing that a program does that cannot be done by hand. (Whether or not it is practical to do so, is a different question.) So, just as with electronics, a good way to understand some algorithm in programming is to just sit down with paper and some items in front of you and just do things, manually, with your own hands. That almost always gets the point across, deeply inside. And then the mystery goes away.
Knowing the name of something is NOT the same as knowing something. The best way to know something is to watch and observe it. So let's look at the device.
LM317 Internal Voltage Reference
Internally, the device includes a very special type of voltage reference which is set for approximately \$1.25\:\text{V}\$. It's not easy to design one of these, by the way. Especially if you want the voltage reference to stay constant over a wide range of operating temperatures and variations in ICs during manufacture and over a long time period. Here's what the datasheet says about it:

You can see that for a wide range of output currents, input voltages, and temperatures (see the note), this voltage is guaranteed to stay between \$1.2\:\text{V}\$ and \$1.3\:\text{V}\$. That's quite an achievement.
To make this voltage reference work well, the designers also needed some kind of current source. The reason is that in order to make such a good voltage reference they also need to provide a relatively predictable current flowing through it. (Remember, you are providing an input voltage anywhere from \$3\:\text{V}\$ to \$40\:\text{V}\$.) So there is also a current source that provides a predictable current through the voltage reference in order to make this work out well. You can see this fact from this part of the datasheet:

The current source they use sources its current from the IN pin. But that current must leave by way of some other pin -- in this case, namely the ADJUST pin. So this current source's current is called the "ADJUST" terminal current. You are supposed to keep this fact in mind when using the device. You must provide a means for this current source's current to leave the device and go towards the ground reference.
Let's recap. For this voltage regulator to do its job, the designers felt they needed to include an internal (hidden) voltage reference. (They need it so they can use it to compare against and then decide how to "regulate" the voltage you want -- I'll discuss those details, soon.) In order to make a good internal voltage reference, they needed a current source. Because of that, they also needed to let you know that you must help them by sinking that current via the ADJUST pin. So they specify that, as well.
You now have to keep two things in your mind: (1) voltage reference; and, (2) adjust pin current. But the ADJUST pin current is just a consequence of providing that voltage reference. So the main thing to keep in mind, in order to understand the device, is the voltage reference (and not the ADJUST pin current, which is a necessary evil, so to speak.)
That's just one of the internal resources in the device. It also includes some special circuitry to protect against too much current and to protect against serious over-heating in operation. So you get thermal protection, built into the device, too.
Voltage Regulation Method
With the above understood, the basic idea behind the LM317 is the following:

simulate this circuit – Schematic created using CircuitLab
The opamp is continually observing both its (+) and (-) inputs and it adjusts its output so that these two inputs have the same voltage. By inspection, you can see that the (+) input will be about \$1.25\:\text{V}\$ above the ADJUST pin voltage. So this means that the output voltage will also be about \$1.25\:\text{V}\$ above the ADJUST pin voltage when everything is working right.
This is the most important thing to understand! So let me repeat it. The LM317 uses the internal voltage reference to set the (+) input about \$1.25\:\text{V}\$ above the ADJUST pin voltage and then uses the opamp's behavior to then force OUT to also be about \$1.25\:\text{V}\$ above the ADJUST pin voltage.
The is the crux in understanding how it works. Make sure you run this through your head multiple times. Drill it in.
Using the LM317
At this point, it's a good idea to realize something else now. The LM317 cannot see \$R_2\$. It has no idea what you are using there. All it is doing is struggling to make sure that the OUT pin is about \$1.25\:\text{V}\$ above the ADJUST pin by letting more or less current flow from the IN pin to the OUT pin (via the transistor [it really is a Darlington instead of a single BJT as I showed.])
Since the LM317 is continually adjusting OUT such that it is always about \$1.25\:\text{V}\$ above the ADJUST pin voltage, placing \$R_1\$ across OUT and ADJUST causes a current in \$R_1\$ which is \$I_{R_1}\approx \frac{1.25\:\text{V}}{R_1}\$.
\$I_{R_1}\$ is added now to the ADJUST pin current, which is flowing out of the ADJUST pin and will be added to the current flowing via \$R_1\$. (Remember, this is the current that was required in order to make a good voltage reference inside of the LM317.)
In your example, \$I_{R_1}\approx 5.2\:\text{mA}\$. The ADJUST pin current adds as much as \$100\:\mu\text{A}\$ to that (though it might also add a lot less.) All of this current must be allowed to reach the ground reference.
In general, you want to make sure that this ADJUST pin current
variation is small when compared to \$I_{R_1}\$, so that its
variation doesn't make much difference to the output voltage of your
regulator circuit. Note that in your circuit case, this is reasonably
true. So now you understand better why that particular value for
\$R_1\$ was selected.
In most adjustable voltage circuits, sinking this current is handled by using a variable resistor (potentiometer) with one end tied to ground and the other end to the shared node of the ADJUST pin and one end of \$R_1\$. The current (which we expect to be somewhere between about \$5.2\:\text{mA}\$ and \$5.3\:\text{mA}\$ here) must now pass through this potentiometer. In doing so, it creates a voltage drop across it. That voltage drop gets added to the voltage drop across \$R_1\$ (which is fixed by design in the LM317) and must, by definition, be the voltage at the OUT pin.
With \$R_2\$ allowed to be up to \$5\:\text{k}\Omega\$, you can adjust the voltage drop across \$R_2\$ to be up to \$26-27\:\text{V}\$. Adding the remaining \$\approx 1.25\:\text{V}\$ means that the voltage at OUT (with reference to ground) can be theoretically as high as somewhere from \$27.2\:\text{V}\$ to \$28.3\:\text{V}\$.
However, to reach those peak voltages you'd have to have an input supply that is higher. Under the recommended operating conditions you can see the following:

So this means that to reach the maximum that the potentiometer and the value of \$R_1\$ promises, you'd need to have an input supply voltage of about \$32\:\text{V}\$.
Other Uses
Now that you understand this much, you might want to consider one more thought about the LM317. It can also be used as a current source for, say, charging a rechargeable battery. If you replace \$R_2\$ with a rechargeable battery, for example, then you can select a value for \$R_1\$ that will generate the right current for recharging it. The LM317 will keep adjusting things so that the voltage across \$R_1\$ is constant and this implies a constant current in \$R_1\$. Since all of that current must reach ground via a path you provide, using a battery in that path means it will get a constant current for recharging it. (There are other problems, of course. You'd need to monitor the charging process and stop it when the battery is charged or no longer requires a constant current. But the point remains -- the LM317 can also be used as a constant current source instead of a constant voltage source.)