I am not completely sure, but I did a brief google search. It is not illegal in the US (the Supreme Court ruled in 1988), but the municipalities might deem it illegal. It is fairly common to have trash pickers come around the day before our trash is picked up. I do not live in an HOA, I would suspect that HOAs would not like trash picking. Most dumpsters are on private property, so if the owners dislikes the dumpster diving, you could be charged with trespassing. I will say that I have had a homeless person ask me if he could look in our dumpster at the store I work in occasionally (we don’t care).
I have nothing to do with law.