There are number of laws that can potentially make it illegal to engage in dumpster diving in a particular place. First, many cities that provide municipal garbage collection services also have ordinances in place that prohibit private collection or transportation of trash or refuse, whether it was collected from private or public property. Similarly, the city may have ordinances that prohibit scavenging in city landfills or city garbage cans and dumpsters, unless the diver has a contract with the city or some other form of permission.
Second, municipal codes and state laws prohibiting trespassing can make it impossible to legally dumpster dive, because the diver does not have permission to enter the property where the dumpster is standing. Very often, trespassing laws cover so much of the available dumpster population that there won't be many of them available to dive in. Even if a dumpster appears to be on public property, if it is locked, then the owner is sending the message that the contents are intended to remain private and protected and it would be unwise to assume that removing and taking anything that it in the dumpster is legal.
Third, sometimes dumpster diving is a way to gather individual personal private information that is then used to invade bank accounts or steal credit information. Identity theft is illegal, and it is not a defense to say that the information was found abandoned in a dumpster, or something along those lines.
Finally, there is a U.S. Supreme Court case called California vs. Greenwood that is often cited as holding that garbage left out for collection no longer belongs to the person who put it out there, and therefore, taking it is not illegal. One problem with relying on that case is that its holding is actually different, and more narrow, than that. What the case really means is that a person who puts garbage out for collection cannot claim later that the police violated his or her constitutional rights by looking at it. But the holding in California vs Greenwood doesn't mean that civilians can go digging in other peoples' garbage. Furthermore, the Washington Supreme Court rejected the analysis of the Greenwood case. Here in Washington, under our own state constitution, it IS an invasion of privacy if police go rifling through the garbage people leave out to be collected.
Having said all of that, dumpster diving is a common practice in many areas. But even if the police don't enforce the laws, individual property owners may react unfavorably to it, and in some areas, there are unwritten unofficial codes of conduct for dumpster diving. None of this has anything to do with whether it is legal, but could have a lot to do with whether a person will be arrested or charged for dumpster diving.
Every person and every case is unique and the information I provide on this forum is not a substitute for consulting with an attorney licensed in your jurisdiction to obtain appropriate legal advice specific to your situation. Any information I have provided is of a general nature. It is not legal advice and should not be construed as such. I am unable to give you legal advice on this forum. Further, I am not your lawyer and by providing information on this forum, I am not agreeing to enter an attorney-client relationship with you. Communications on this forum are not privileged or confidential and should not be treated as such. It is unwise to disclose information of a confidential or personal nature on this forum. If you are unable to afford an attorney in a criminal matter, the court should be able to appoint counsel for you at no cost to you. Also, most state bar associations can provide contact information for free or low-cost legal advice.
It may depend upon where the garbage cans or dumpsters are located.. if they are on the curbside.. most likely not..
If they are on private property that is walled off or not public then they can get you for trespassing..
Please note that I answered this question with general knowlege of the law and with limited disclosure from you, my answer does not create an attorney-client relationship and I cannot be held responsible for how you, the asker, use the information provided. If you want to contact me directly and retain my services you may through my listing on this site or at 248-901-0750 or email@example.com.