In my professional opinion, there are two main reasons.
1. Portfolio building.
When applying for new projects or jobs, these open-source projects can be listed in their portfolio as a frame of reference for their skills. This also makes the developer look good in the eyes of anyone reviewing their skillset.
2. Skill retention/development.
Programming/web development is just like anything else. The more frequently you practice, the better you'll be. Programming is a skill that's highly dependent on consistency. You learn, even as an advanced developer, on a constant basis.
A programmer working on an open-source project for free is in a win-win situation.