The actual problem
How does a transistor inverter work?
Perhaps this is the most important question in analog electronics just because this circuit represents the most basic transistor amplifier. So the question actually is, "How does a transistor amplifier work?"
And since amplification is actually a voltage regulation, the question is really, "How can we control a voltage through another voltage?"
And only last is the question of why and how the circuit inverts the input voltage...
A bit of history
Interestingly, this problem arose a long time ago. Sometime in the middle of the 19th century, people felt the need to reduce the electrical voltage... and they did. To understand the meaning of all this, let us trace the evolution of this idea from the simple electric circuit of the time to the electronic circuit of today.
Building scenario
I will do it in six consecutive steps illustrating them with simple conceptual diagrams. The values of the quantities are approximate for the purpose of this intuitive explanation.
Reducing voltage divider
Imagine the first three steps (schematics) take place in the 19th century.
STEP 1: Connecting a constant voltage source. We have a source of constant voltage Vcc1 and apply this voltage to a true voltage load (voltmeter VM1) which has a very high resistance and therefore does not consume any current. The voltage is "excessively" high; so our task is to reduce it.

simulate this circuit – Schematic created using CircuitLab
STEP 2: Trying to remove some voltage through resistance. The first idea that comes to mind is to include a resistor R in series with the voltage source Vcc2 to take away part of its voltage. What is our surprise, however, when we see that the voltage after the resistor does not change. The problem is that current does not flow through the resistor... there is no voltage drop across the resistor... and the voltage does not change... as though the resistor is not a resistor.
STEP 3: Causing current to flow. So we have to cause a current to flow in the circuit. For this purpose, we connect a second resistor R2 in series with the first R1 and in parallel with the "load" VM3.
Regulating voltage divider
Now imagine that the next three steps (schematics) take place both in the 19th and 21st centuries.
To change the voltage, we have three options - to change the resistance R1, R2 or both. If we were in the 19th century, we would manually change the resistance by moving the wiper of the so-called "rheostat" (the diagrams on the left below) but in current electronic circuits, e.g. in the OP's inverter, this has to be done automatically using something like a "voltage-controlled resistor" (the diagrams on the right below). A transistor can serve as such a device. It is an "enhancement-mode resistor" which means that when the control voltage increases, its resistance decreases.
STEP 4: Changing R2. So when decreasng R2 (on the left circuit, in the 19th century:-) or increasing Q2's base-emitter voltage (on the right circuit), the output voltage decreases... and the (OP's) circuit is inverting.

simulate this circuit
STEP 5: Changing R1. And v.v., when decreasng R1 (on the left circuit) or increasing Q1's base-emitter voltage (on the right circuit), the output voltage increases... and we can say that, in this sense, the circuit is non-inverting.

simulate this circuit
STEP 6: Changing both R1 and R2. Finally, a brilliant idea occurred to us - to simultaneously change R1 and R2 (on the left) and V1 and V2 (on the right) in the opposite direction. The so-called "complementary circuit" without resistors is obtained, which in both states does not consume current.

simulate this circuit
What is OP' circuit solution?
This is the configuration we discussed in step 4. The regulator (Q2) is connected at the bottom of the "voltage divider" so that as the input voltage increases, its "resistance" decreases and the output voltage decreases accordingly. In the extreme two cases, at a high input voltage the output is low and conversely at a low input voltage the output is high, i.e. the circuit inverts.
The resistance of the transistor is non-linear but this is not essential to understanding the principle.