Very clear here, but if the SE were to factor in the validity of the code for all websites it has indexed the search results would be very different and probably worse. Why would a more valid website be more relevant? It wouldn't and their in lies the issue and problems for the search engines.
The relevancy of the SERP"s is so much more important to them than whether a website is valid or not.
Now if all things were consider for tow websites and most current
SEO factors were equal: relevancy, content, IBL's, etc and then they choose to list one website over another because it was more valid than the other, feel free to. It will never get more than that.