As stated earlier good consultants will do write quality code. However, many consultants don't have to live with the code they generate. What I mean by this is that consultants write code for a company and never have to maintain this code. So many consultants focus on solving a problem.
Companies that hire consultants should have a procedure for internal developers to participate in code reviews with a consultant. Also, you can require consultants to follow coding standards and enforce the use of unit tests. If a consultant is required to write quality code they will write it or attempt to write it. I believe too many companies provide business, system, and functionality requirements to the developer, and then don't maintain project visibility.
At our company we outsourced an project that required a company to create a web application. We discussed the requirements the cost and what the our quality expectations. It wasn't until the project was near the end when we took it over internally. we had noticed none of our coding standards were followed. The application structure was horrible. There were no tests, documentation, or structure to the code. It took us weeks to sort through the application before we understood what was going on. It was soo bad we were affraid to touch parts of the code, because we didn't know the consequence of changing it.
During our rhetorspective we identified our main issue was lack of involvement with the consultant, and lack of visibility. If we were able to review code early and frequent we could have prevented this in the long run. Also, we could have enforced our coding standards. Also, had a developer or development team representative participated in the project we could have made recommendations and had them write unit tests.
The key point is that there are things the company can do to enforce quality code. It isn't just the consultants responsibilty it is the company's responsibilty as they are the ones that will live with and maintain the final product.
Also note that every consultant is different and has a different skill levels and understanding of code quality.