Short answer? Because many (if not most) programming jobs turn into a soul-sucking slow torture of meetings, overbearing process, second-rate solutions in the name of compromise and dealing with cluessclueless and/or unreasonable people who often view what you do as an unfortunate cost centre.
Whereas on SO you're generally talking to a better class of programmers. I say this because those who bother to read and post on SO are generally more interested in self-development than perhaps the average Joe (Programmer). To such people learning something and teaching something to someone who is generally interested is more rewarding.