Generally speaking dumpsters are on private property and you have the same rights to protect your property interests as you would with someone trespassing/ damaging any other portion of your property. If the dumpster is on property owned by the overall store/ complex owner they have a right to protect their property. And in the case of the dumpster being in the public right-of-way...not normally the case...the municipality has an interest in not allowing that sort of activity. It might also be true that the waste companies which own the dumpsters themselves have them marked for no tresspassing to protect themselves from liability. So, while I don't know that 'dumpster diving' per se is illegal, it is certainly an activity that you can stop.