Is it worth patenting something before submitting to the W3C, even if it's a royalty free patent?
The basic answer to your question is that all parties who submit ideas to a W3C specifications development process agree to license those patents to anyone who creates or uses an implementation of the specification. (The full license is here.) This is simplified a bit, and will depend on how you submit the idea, but that is the basic goal of the policy.
So you will not get much (if any) revenue from patenting an idea that you then submit to W3C. If you do file the patent, you can still use it against people who are not implementing the relevant W3C specification, so depending on the nature of the patent you could perhaps use it against competitors to the specification. But that is highly speculative at that point.
If your goal is to protect the specification (i.e., you want to support W3C), your best bet is not to file a patent, but rather to provide very good detail on the patentable idea to relevant, public W3C forums as quickly as possible. Publishing it in this way makes it prior art for future patents as quickly as possible, and would help W3C or supporters of W3C should someone try to later patent the same idea. This is also much cheaper and easier than filing a patent, which is an expensive, multi-year process.
This process is known as defensive publication. There are tips for writing good defensive publications at defensivepublications.org (though that site is down right now - I'll update this with better links when I have a chance.)
Note that this is not the case for all specifications or standards bodies; they all have different rules about this sort of thing. For example some allow for royalties, or some have compliance rules; i.e., only compliant implementations get licenses, so anyone who embraces/extends the specification might be sued.
In the more general case of submitting to any random standards body - that submission will likely be considered prior art for terms of patent-ability. So, if you do submit to the standards body BEFORE doing any patent filings, it is quite possible that you'll be unable to patent the thing later. Whether this is a good or bad thing depends on the body in question and their views on patented materials in a standard.