These are good questions to ask yourself.
The most succinct answer to your questions is: Mass Balance and Energy Balance.
Wall friction will actually cause a subsonic flow of gas through a
pipe to accelerate up to M = 1 (this is still counter-intuitive to
me).
Gas bulk velocity increases but mass flow rate remains the same.
In a gas transmission pipeline friction causes the pressure of gas to drop as the gas travels down the pipeline. This pressure drop causes a decrease in gas density and a decrease in gas temperature. For steady state flow, the mass flux past any point along the length of the pipeline must be equal to all other points. The same cannot be said for velocity since "conservation of velocity" isn't a thing. Here is an equation for gas velocity $v_{gas}$, gas volumetric flowrate $\dot{V}$, pipe cross-sectional area $A_{pipe}$, gas mass flowrate $\dot{m}_{gas}$, and gas density $\rho_{gas}$:
$$v_{gas}(x)=\frac{\dot{V}_{gas}}{A_{pipe}}=\frac{\dot{m}_{gas}}{\rho_{gas}(P,T) \cdot A_{pipe}}$$
If the mass flowrate $\dot{m}_{gas}$ is held constant and the pipe is rigid ($A_{pipe}$ held constant), then a decrease in gas density will cause the velocity to increase proportionally. Eventually this increase in gas velocity will continue until $M=1$, available pressure drop falls to zero, or the gas reaches the end of the pipeline (and consumed by the customer).
If the mass flowrate $\dot{m}_{gad}$ is not held constant, then it may be that $M=1$ is never reached.
The textbooks I've skimmed generally say "if there is still pipe
length left or heat addition past the point of M = 1, then the inlet
conditions must spontaneously change such that the flow reaches M = 1
at the end of the pipe." But they do not explain what these changes
are or what mechanism enforces them.
As someone who worked with pipeline models in the oil and gas industry, here's my take. The book seems to be talking about an edge-case scenario where you purposefully let pipeline pressure fall until you the gas mach number $M$ manages to reach $1$. It seems to be a way of indirectly explaining the nature of choked flow in few words.
Here are more than a few words:
The changes to inlet conditions would be to gas temperature, pressure, or flow rate in order to raise the speed of sound or decrease bulk gas velocity until the $M=1$ point hits the end of the pipe.
The mechanism that enforces this conservation of mass and energy. In my experience when flow through a pipe reaches $M=1$, no further increase in mass flow rate of a given gas composition is possible unless the gas temperature is increased. The point at which $M=1$ is like the event horizon of a black hole: no information can be transmitted downstream via pressure (sound) beyond that point.
I believe this point-of-no-return for pressure information at a $M=1$ point in a pipeline is because if you try to pump gas molecules through a pipe beyond their speed of sound, the excess energy dumped into the pipeline by the pump to perform this acceleration goes into raising the gas temperature instead of the bulk gas velocity in a single direction along the pipe. If small supersonic regions where $M>1$ of the gas do appear, they are quickly dissipated by turbulence due to the presence of the nearby pipe walls, preventing other groups of gas molecules from achieving $M>1$.
For example, let's say I have a positive displacement pump that pushed a constant mass flow rate of gas into a pipeline and I disabled all high discharge pressure and temperature shutdown safety mechanisms. Let's say the pipeline's primary outlet valve were closed due to a downstream equipment problem. At some point a pressure relief valve along the pipeline opens and begins venting gas to atmosphere. As pipeline pressure builds up, mass flow rate through the relief valve increases. Increased mass flow rate means increased gas bulk velocity which means increased $M$ at the relief valve. $M$ would rise until $M=1$. However, at $M=1$, additional increases in relief valve's inlet pressure cannot increase the mass flow rate any further for the reason I stated earlier. Some increase in mass flow rate would be achieved due to increased temperature caused by the adiabatic heating of the pipeline gas (as the runaway pump continued to shove gas into the pipeline) but this does not raise $M$ since the speed of sound rises with rising temperature (both temperature and speed of sound are functions of the root mean square of gas molecule velocities). Eventually the flow rate through the pressure relief valve (hopefully one designed to handle the flow of the runaway pump) would stabilize with $M=1$ at its orifice (the "end of the pipe").
The principle I'm trying to get at is that the system will adjust in response to whatever variables you fix. If you try to fix more variables than degrees of freedom you have available in your system, then you'll find that you cannot achieve control of one of the variables.
What if I am controlling the inlet conditions to be a certain
pressure? Then what happens at the end of a rough walled pipe if the
flow reaches M = 1 in the middle? Or what if I forcibly add more heat
past the M=1 point (in an initially subsonic flow) where the inlet
pressure is fixed? Physically, what will happen?
$M=1$ requires energy to sustain. I know this because I have worked near 15 MMSCFD (million standard cubic feet per day, or 17,658 standard cubic meters per hour) relief valves going off: you can hear its scream for miles (the extreme turbulence of gas from within the piping). In a pipeline, that energy is provided by pressure drop. This pressure drop can be provided by increasing upstream pressure with a pump/reservoir or by decreasing downstream pressure ("backpressure"). Heating a section of piping may increase pressure.
But let's explore a situation that attempts to hit all your question's theoretical requirements. Let's say we have a new empty pipeline at atmospheric pressure. Let's say we decide to violently fill it with gas from a set of compressors and heat exchangers so powerful that we can instantly and continuously maintain a controlled inlet gas temperature and pressure. It will be a violent affair but let's imagine this crazy boundary condition for this dynamic model. The pipeline is initially quiet and uniformly at $1 atm$. We start the compressors and the inlet pressure and temperature are instantly on target at the mouth of the pipeline. The gas immediately enters the pipeline causing a high pressure wave of gas to flow at its speed of sound. This speed of sound varies with the front's temperature. The front temperature is much cooler than the inlet temperature due to the Joule-Thompson effect. All the while the compressors and heat exchangers stubbornly maintain a constant inlet pressure and temperature, injecting enormous quantities of heat and mass, although the mass flow rate decreases gradually. At some point in time there is a situation where $M=1$ is located midway along the pipeline length. No gas has been able to travel downstream of this point since pressure information cannot be transmitted downstream through the $M=1$ point. Pressure downstream of $M=1$ remains at atmospheric pressure. Adding heat past the $M=1$ point doesn't do anything but warm empty pipe.
So why aren't all our natural gas pipelines carrying gas at the speed
of sound? Or why not even our water pipes?
Because natural gas pipeline companies want to maximize mass flowrate while minimizing cost within government regulations. Mass flowrate is higher if gas density within the pipeline is higher. Gas density for natural gas nearing $M=1$ is low and can cause problems such as hydrate formation for long runs of pipe.
As for water pipes, liquid water flowing at high speeds erodes piping. It is also incompressible so you don't get much benefit at all in terms of increased density for transferring it at higher pressures. Transporting water in its vapor phase for distances long enough for pressure-drop-induced $M=1$ situations to occur is rare and expensive (especially since steam systems require insulation and boilers to prevent condensation back to its liquid state).