I had a dog that used to do this all the time. The Vet said it was because something was missing in his diet that caused him to eat at the litter buffet. I tried a bunch of different foods with various vitamins, vitamin supplements, special treats, etc. I never could get him to stop. The vet said it wasn’t harmful, but understandably distressing. Especially if they want to lick your face shortly there after!
A Cat’s metabolism is designed for high fat and high proteins. Cats aren’t too good with carbohydrates. That’s why cat food is a lot higher in protein and fat, and it’s why dogs love to get their paws on it. That’s also the reason for the ammonia smell in the litter box. One of the side effects of protein catabolism is ammonia production. Maybe increase the protein in your dog’s diet (beef treats, a little bacon treat, etc) and see if that helps?
In the end, it could just be he just likes it the way a kid likes candy.