It's a bit like a tower. At the base is the kernel. On top of that are all the basic tools. Next is all the software that you run on the computer. The answers are as varied as the people who contribute.
Some people like to help others.
Many write programs to learn more about computers. More and more people are looking for ways to avoid the inflated price of commercial software. A growing crowd contribute as a thank you for all the great free software they've received from others. Many in academia create free software to help get the results of their research into wider use. Of course, a lot of us just find it great fun.