He knows he shouldn't, because you can tell by his demeanor as soon as you open the door (he will go into his crate) if he has done it.
My guess is that you have reacted angrily to the garbage in the past when you've come home. So your pup knows that you don't like garbage. He doesn't know that you don't like him going into the garbage.
It's a subtle distinction, but reacting to something your dog has done minutes or hours after the fact is rather useless. This is a situation that simply requires management.
I had a dog that was on the streets (starving) for about 6 months before animal control picked her up and I adopted her. She was a forager in the garbage and a counter cruiser.
I finally found a garbage can that she could NOT lift the lid. And we established what we called The Grover Zone. Anything within 24" of the edge of any counter or table was hers (practically speaking), so we didn't leave it there.
In Grover's case, she was terrified to be crated, so we worked around that, but it was a substantial inconvenience.
Rubbermaid bins seal well and work well for both garbage and food storage, since you don't have a lot of storage. They're not super attractive, but they work.
Every time your dog gets into the garbage or on the counter and finds even the slightest bit of tasty food (or even a wrapper), he is TRAINING HIMSELF that this is a good behavior. That's why you're seeing the behavior more and more. It's as though you are standing there handing him a treat every time he does it. You need to break that cycle completely. Crating is the easiest way. With some dogs, the behavior will simply extinguish itself over months (actually it may take a year or more) because you will have stopped the "training." For other dogs, it will be a life-long challenge.
I've never met anyone who was able to train their dog to stop counter surfing (without managing and extinguishing over a long period of time). In fact, a friend of mine, a very capable professional trainer, uses an indoor Invisible Fence product that keeps her 10 yr old dog out of the kitchen because she's a counter cruiser. This dog is one of the best trained dogs you could ever hope to meet.
This is the dog's one fault. I think it's rather charming, in that she's not a perfect dog. But I don't live with her either.