Since you ask about Stack Exchange (SE) sites in general: Many companies are usignusing Stack Overflow Teams as a way to internally help their programmers with knowledge. For example, there are companies using C++ that have complex templating questions to answer and in the process of doing it they use Stack Overflow to find existing answers and if notthere aren't any they add high quality answers that otherwise might not exist.
With regards to Ask Ubuntu in specific, I think a lot of people have had a random question related to Ubuntu at one point and found a great answer here already. This saved them a lot of time and headache. Many experienced Linux users also know that it's very likelyunlikely they know everything about Linux, but the parts they do know they are glad to help out with. It's not uncommon to spend a few minutes, but in the process save someone else hours of their time. It's kind of like carrying the groceries for an elderly person.
Like Mark McDonald said it's also because the points. I'd be lying if I said I didn't like increasing the points and earning the badges. Over time, I think that effect fades, but by the time it's diminished you've already seen the impact you can have and will likely keep doing it.
It's also worth mentioning I actively shame lots of people in the "real world" for not contributing to Stack Exchange sites and in the past if an employer questions my time spent on a SE sites I will simply ask them if they want me to stop using SE sites to resolve questions. Obviously, they don't want me figuring everything out in a bubble so they desire I keep using SE sites, at which point it illustrates the point: How do you think a system of exchanging knowledge can work if everyone only takes and never gives?