Admittedly, there is a lot more to good coding than just its validity. Also, there are reasons why you may use "invalid" code, e.g. to use the css3 "radius" attribute in an html4/css2 page. The major browsers generally support it (not IE8 or earlier) so why not use it? But that is not a good reason for not validating your code.
All invalid code puts you at the mercy of the error handling of the different browsers. They will, in some cases, handle the "error" consistently and beneficially (as above), but generally not. So validating the code is a necessary part of ensuring consistent behaviour on a range of browsers.