The primary purpose is to "Make The Internet a Better Place™". What this means is that the Q&As should be of the form that are useful to others. People searching for a conceptual explanation or the resolution of an apparent paradox should find this site and be helped here.
This has a long history. If you've ever googled for help with something and come across a forum, you might have been frustrated by the signal-to-noise ratio on that forum. I recall coming across tons of tangential discussion, and sometimes pages and pages of discourse which reaches no resolution. Besides that, many of these are cluttered with duplicates and one-time problems that are really too specific for anyone else to benefit. Forums are useful to the people asking questions and the handful of community members participating in the discussion. But the wider audience from the Internet has a hard time with forums.
Stack Exchange tries to do away with that, by keeping posts focused and only allowing posts that will help many people. This was the essence behind the "Too Localized" close reason that many of you may remember, — the point was that while the answers may help the OP, there's a very little chance of it helping anyone else.
This is also one of the main reasons why we close homework. Besides the no-effort-please-do-my-work-for-me, homework questions don't help any other visitors. While the answers may be conceptual, it is pretty hard for someone with the conceptual question to find the homework problem via Google or otherwise, as the question focuses on the problem, not the concept 1. As for people who want help with the same homework problem, well, that's pretty rare.
So the main purpose is to also help people other than the OP, people who will come to the Q&A after searching related terms.
But that's just the primary purpose. As you mentioned, fun is another factor2, as is encouraging interest and conceptual education. The "fun" bit extends itself; I personally don't participate just because it's "fun". I write answers because my own understanding is strengthened by doing so3, not just to help the OP and the other readers.
I'm not intending to say that we aren't here to help each other. We are. The community feeling is a great thing, and helping each other learn physics is a good goal. But one should try to have a look a the larger picture, helping a couple of people on site is dwarfed by the countless other non-members we help.
Research is a different beast. Our non mainstream policy, in its attempts to be as objective as possible to avoid unnecessary arguments, stops us from developing new physics4. I guess this is OK, because frankly speaking, the people here have better channels to develop new physics; by discussing with colleagues and collaborators. The ones who choose to try to develop the theory here are usually the type that are proposing some non mainstream ideas. Besides all this, the limitation of discussion on the main site is a damper here, though that is easily remedied with chat.
Note that this is in no way saying that research level questions are discouraged, just that using the site as a platform to develop new theories collaboratively is discouraged.
1. Which is why we encourage making HW question conceptual; people will actually find the question then
2. Don't let this blog post tell you otherwise ;-)
3. The act of codifying nebulous thoughts on a topic into clear English is something that seems to immediately highlight one's own conceptual misunderstandings and inadequacies.
Neither does MathOverflow, they have a policy against open questions and the like, and they still maintain a good level of research-level questions. MathOverflow disallows well known open problems, but they don't seem to have any research being done on site, even if the posts may inspire research.