Cleaning up you site's code makes it easier for search engine spiders to index your site. Although not all messy code will cause problems for your search engine rankings, some of them can keep web spiders from indexing your web pages.
Search engines have to parse the HTML code of your web site to find the relevant content. If your HTML code contains errors, search engines might not be able to find the content on the page, and there ends your SEO efforts and quest for high rankings of that page. Search engine crawler programs obey HTML standards. They only can index your web site if it is compliant to the HTML standard. If there’s a mistake in your web page code, they might stop crawling your web site and they might lose what they’ve collected so far because of the error.
Valid CSS makes pages "lighter" in weight, and decreasing the code-to-content ratio. Done properly, this can make your entire site easier and more efficient to index.