Stack Overflow's badge system follows the well known trend of Gamification, defined as "the application of game-design elements and game principles in non-game contexts".
There are plenty of articles and studies on why gamification works which I'll link to below.
In Short: People like earning achievements because it provides a clear set of goals to aim for, then gives positive feedback when those goals are accomplished. If you look at Stack Overflow's badge list, you can see that many of them serve as reasonable goals for new users to reach.
It's a positive feedback loop. A user earns a badge for good behavior, encouraging them to continue that behavior, which leads to earning more badges, which hopefully leads to more good behavior.
Further reading:
Further reading:
- Psychology of Games: Why Do Achievements, Trophies, and Badges Work?
- Extra Credits: Gamification - How the Principles of Play Apply to Real Life
- Wikipedia: Gamification