Perhaps a cultural difference, or more my age, but I seemed to notice it becoming more prevalent about the TW era.
Certainly as a youngster we never did it and I grew up in proper clubs, and even now its rare to see the old lads at my club do it, although the kids seem to have picked up the habit. You wear a hat for reason and I really don't want to shake someone's greasy hand that they have just run through their sweaty hair. I have looked at numerous old you tube clips of majors and other significant events, and its fairly common to see the old greats of the game leave their hats on when shaking hands on the home green.
I'm sure some diligent person will do the work and come up with a time when and where it first started to catch on.
But in the clubhouse however, whoa that's a hangin offence.