There are some exceptions: it is illegal to dumpster dive if you are trespassing on the grounds of any business, government building, or private home. As a part of New York City, you should follow and respect property rights to avoid inconvenience. The boundaries of the legality of Dumpster diving should be respected.
Read more: https://whatisnotlegal.com/is-dumpster-diving-illegal-in-new-york/