The precise meaning of many if not most words changes over time, for various reasons. There's a slight tendency not to revert to an earlier meaning simply because that would imply the direct negation of whatever caused the original change.
The example gay was originally coined within the homosexual community, so obviously it didn't originally have pejorative associations. They just arose naturally when the new meaning became more widespread, because the general population still includes some homophobes. Younger speakers tend to be less homophobic, and many now use gay as a general-purpose insult without necessarily even thinking about sexual orientation.