You keep your hands out of your pockets so they know you don't have something in hand to kill them, just like you shake with your right hand to make sure you're unarmed (silly fools! Don't they know I'm left-handed

)
Really, pretty much all our kind etiquette came from our distrust of others. Don't eat until everyone has their meal is to keep someone from poisoning all the food and serving the target first, for example.
We don't need shoes, or a shirt indoors either, but we don't take those off. I think the hat thing has more to do with having your face entirely unobstructed. Otherwise, it seems as though you're trying to hide your face(and possibly hide certain facial expressions which might betray your thoughts).
Bingo. It's to make yourself easily identifiable as a friendly when invited into another's house.
Here's one: Why is it considered rude to some people to put your elbows on the dinner table?
You're claiming your territory when you put your elbows on the table, instead of conceding to the owner when at a dinner party and showing trust. You'll notice this trend continues in prisons where inmates will often eat with their full arms on the table to "claim" their space and protect themselves.
Once again, the real reason is because we don't trust each other
