I’ve resorted to Stackoverflow dozens of times (at least) for answers to questions that I couldn’t solve myself. Most often, my questions were about using third-party software that was poorly documented, and my answers came from people who’d climbed the same hill and somehow figured it out. (Or, wrote / maintained that software.)
So if I see something in Stackoverflow I can answer, I will because I want to give back to the community that’s helped me.
There are many reasons; Why do you play videogames? To some people, the reputation is like the score of a game. It certainly does not hurt on your CV or LinkedIn profile!
Also, putting something you already know in concise writing (or any other form suitable to explain it to someone else) helps you order your ideas and “solidify” them better in your own head.
So, the answer could be “for the same reason that they ask questions: To become a better software engineer”.