Prisons resemble factories, hospitals, and schools in that, since the eighteenth century, they have been designed to condition people to internalize the values of the state (i.e., the values of the people in power). They all do this by using surveillance: people in all of these institutions are constantly watched, measured, and evaluated by others. To "succeed" in any of these environments, an individual has, above all, to demonstrate that they can self-regulate. That means they must exhibit model behavior, without any threat of imminent physical punishment.
Through this method, Foucault argues, the state enforces its will by conditioning people to change themselves. The state infrequently uses physical punishment; instead, Foucault says, the state changes our mode of thought in such a way as to encourage obedience and conformity. This, he says, is more cruel than the punishments of the past that we thought were barbaric. Damaging a person's body leaves them free to think their own thoughts. Molding their thoughts, however, leaves them permanently changed and damaged.
Several issues can be pointed out in Foucault's sweeping histories—or, as he called them, "archeologies"—of knowledge. For instance, he posits a concept of body/mind dualism, when the relationship between the body and the mind is much more complicated. However, his writing is immensely provocative and therefore worth contemplating. His thoughts about how we internalize the will of the state is relevant today in terms of the conversation about internet and electronic surveillance: does the very fact we are being watched cause us to self-censor?
But the larger point addressed in this question is that schools, hospitals, and factories function on the same premises as prisons through use of surveillance and the demand for self-regulation.