Flashers are a strange societal nuisance of yesteryear. I can't speak to any psychosexual pathology, but from what I've gathered from anecdotes from older family members it was just something that you could encounter living in cities or maybe the suburbs.
As to why? It was always attributed to "weirdos", so probably lots of different reasons ranging from drunk guys daring each other to being mentally unwell and untreated while living on the street. The stereotype is a guy in a trench coat with no pants on who sneaks up on unsuspecting passersby, flashes the goods, then runs off.
I'm sure it still happens but I'd wager that most of people who get a thrill out of it retreated online to sites like Omeagle and Chatroulette. Getting caught can also land you on a registered sex offender list now so I'm sure that has curbed people in the "harmless prank" camp.
Most definitely not the kind of hog posting we endorse here.