As per the downvote tooltip, people vote based on whether or not an answer is useful. How anyone wants to define "useful" is left widely open to interpretation.
Just because an answer has code that compiles, runs, possibly even if it produces the desired output, doesn't necessarily mean that it's a useful answer. While code that isn't correct, and doesn't produce the correct output, usually means that an answer isn't useful, it's not the only thing that can make an answer not useful. Being bad practice, containing major security vulnerabilities, or having significant negative side effects (especially if they won't be immediately apparent), etc., if it is to the point that the reader feels that other readers are going to be worse off for having considered that answer, may well be justification for someone choosing to downvote the post. Whether or not the problems are that significant is, again, open to interpretation.
While a disclaimer can help, personally I find that most readers will ignore such disclaimers, and have a tendency to try very harmful code and continue to use the solution so long as it passes a single test case. Since the disclaimer often doesn't do its job of actually stopping people from using harmful code, I find it's generally not a reason to refrain from downvoting an answer containing a solution I consider harmful. That's my interpretation, of course, and not everyone else has that same interpretation.