In Chicago, it's done to keep the alleys clean. There's a long history of people digging through dumpsters and making messes, providing homes and hospitality for rats. A previous mayor had a real phobia about rats, and made locking up dumpsters a pretty serious rule.