Both are true. A PhD program is a great way to find a chunk of time to dedicate to a problem for a few years. At the same time, we've had contributors who were in high school when they started, through GSoC, and just generally interested folks in the community. On the other end, we've had tenured professors and even retired professors contributing to Julia.
Eventually, it boils down to two things. Find a problem that you want to work on and engage in the community as one-more-minute points out. Second, find a way to support that - PhD, an interested employer, a university, a grant, or perhaps you have are just well off and can do whatever you want!