As I remember it, Foucault's explanation is to turn historical materialist explanation on its head, making the domination of man by man the guiding principle, and the extraction of a surplus only an intermediate goal. Hence he argued that the factories were created on the model of the prisons, for the purpose of creating the necessary means of financial support for the prison system.
In other words, the factory system is an outgrowth of the prison system, and not vice versa.
A superficial reading of the chronology seems to support Foucault - prisons come first, and many of the factory regulations seem to be borrowed from prisons. But chronological priority is not the same as logical priority.
Marx's chapter on the 'bloody legislation' late in Capital, Vol 1, give a good alternative account, to the effect that the early repressive apparatus supplemented the, as yet, unformed power of capital to discipline its subjects through the dull compulsion of the wage. At its apex, capital was less dependent upon outright violence, relying instead on the power of the labour market. In its dotage, by contrast, capital is less and less effective as a means of regulating social action, and hence more and more dependent upon outright oppression to maintain order.
-- Jim heartfield