People exaggerate this in both directions. Some people do say, inaccurately, that H1B holders are unable to change jobs. Others say that nothing prevents them from doing so. Both are inaccurate, though the also both contain some truth.
H1B holders have some limited job mobility. They typically must find a new corporate sponsor, and if they are also being sponsored for a green card, they will typically need to ensure that the new employer will also assume sponsorship. If they are hoping to get that green card, they would be wise to stick with stable employers. Although it used to be the case that an H1B holder would restart the waiting process with a new green card sponsor, that is no longer the case, so at least that is a mild improvement.
The types of jobs an H1B can move to are also restricted. They can pretty much be an engineer/developer here, there, or even over there, but that's about it. Changing fields, dropping out to be a consultant, starting your own business (whether it's a tech company or a sandwich shop) is pretty much out of the question.
The mobility that does exist helps, but overall, I think the restrictions are severe enough that H1Bs really can't be considered free and full participants in a labor market.
The more cynical side of me sees this as entirely deliberate. A RAND study found that the American aversion to STEM graduate degrees is rational and market-driven. I feel that while dev jobs are ok, there's a lot to dislike about them - open offices, back visibility, scrum meetings that limit autonomy and are misused to apply deadline pressure, often soulless and unfulfilling work. I do think that people who are capable of becoming developers are also capable of finding work they prefer outside the field - provided they are free to do so.
Part of the appeal of the H1B is that it creates a population of workers who are, well, not free to do so. Corporations talk about things like "at will employment", but they'll absolutely lobby government to undermine freedom if freedom doesn't suit them.