> If there really is excess demand for a kind of labor, then the labor can borrow enough to pay for it;
You're right, but the reason that doesn't happen is that the price (ie, expected future earnings) is effectively fixed[0], and the current trajectory of that is already on the threshold of discouraging people from entering the field. As it is, a person who enters medical school at the age of 22 can reasonably expect to pay off their final student loan payment in their 40s[1]. That's a pretty hefty gamble to take at that age - you're assuming (against all evidence![2]) that medicine will continue to pay roughly the same in the future as it does today, and based on that assumption, you have to be willing to take a gamble that won't even break even until you're past normal childbearing age. That's a really tough sell, and I say this not hypothetically, but from experience.
It's similar to the "engineering shortage" in Silicon Valley - we know for a literal fact that the largest companies colluded to suppress wages, but simultaneously complain that they can't find enough workers that price. Except, we don't have to take out large amounts of debt before we can start working, whereas would-be doctors do.
[0] Not exactly fixed, but far from an actually competitive market that would allow proper consumption smoothing like you describe
[1] There are a lot of factors that determine this, like which specialty you choose, and where you practice, but that's a pretty reasonable rule-of-thumb estimate for someone who's still only thinking of applying to medical school in the first place.
[2] Physician earnings have been dropping steadily over the last few decades