Because dumpsters are usually located on private premises, dumpster diving is illegal in some parts of the United States, though the law is enforced with varying degrees of rigor. The California v. Greenwood case in the U.S. Supreme Court held that there is no common law expectation of privacy for discarded materials. Dumpster diving per se is probably legal when not specifically prohibited by state or local law.
Police (and possibly other) searches of dumpsters and like discards are not violations; evidence seized in this way has been permitted in many criminal trials. The doctrine is less well established in regard to civil litigation.