If a careless old bat can sue McDonald's for millions because of hot coffee burns, you think a ditsy young trespasser can't do the same thing?
They aren't protecting their garbage, they're protecting their assets. Of course, if you HAD assets, you'd know that!
McDonalds throws away pre-made sandwiches that are still good but not perfect because they've been sitting around waiting for someone to buy them.
And the natural human tendency, if you work at McDonalds, is to fish the sandwich out of the trash rather than throw it away. And if you are dishonest, you may be tempted to make extra sandwiches so you can fish them out of the trash.
So, in order to prevent this from happening, McDonalds will fire you if you take sandwiches out of the trash.
So then, people who throw away sandwiches will carefully arrange them so that they are on top of the trash, so they can come back after work and get them when no one is looking.
Hence the reason that the dumpsters are kept locked. It prevents employee pilferage.