DHAKA—At the Mohammadi Fashion Sweaters Ltd. factory in Bangladesh’s capital, a few dozen workers stand watching as 173 German-made machines knit black sweaters for overseas buyers. Occasionally the workers step in to program designs or clean the machines, but otherwise there is little for humans to do.

It’s a big change from a few years ago, when hundreds of employees could be found standing over manual knitting stations for up to 10 hours a day. Mohammadi’s owners began phasing out such work in 2012, and by last year, the...