A few reasons:
Altruism: They might find it rewarding to share.
Tit for Tat: They might hope that if they share, others share with them
Pride: They might think they get known for their work, their code could be used by many people
See it this way: If you sit around a fire and are the only one with a pack of beer, would you share? Now if you share source code, the situation is even better: By sharing you are not losing anything, you still have your copy of the code.