It depends on where you live and the towns or cities local ordinances and if the dumpster is a public use dumpster or a private use dumpster.
Most towns won't care if you dumpster dive as long as you leave the place as clean if not cleaner than you found it.
If you're trespassing and caught the first time you might just get a trespassing ticket and not get arrested.
In most cases you'll just get a fine and notice to appear in court or pay the fine.
You won't be going to prison for dumpster diving.