There are two possible situations here:
The answerer misunderstood what the question was asking, possibly because the question was unclear, vague and open to multiple interpretations, was lacking sufficient information to be completely confident of the problem, etc. In such a case, clarifying the question is absolutely correct, and downvoting the answer is also entirely appropriate. If you come across such a situation, you should also downvote the incorrect answer, or if it's yours edit it to correct its problems or simply delete it.
The original question was a complete, clear, unambiguous question, that was correctly answered. The OP realizes, after posting the question, that they mistakenly asked a different question than they intended to. They should ask a new question. If you see an edit that is completely changing the question from one to another, you should roll the edit back and inform the author that they can ask a new question if they have a different problem. If an edit war starts, flag for a mod rather than continuing to edit the post.
If your answer in such a situation gets downvoted, there simply isn't anything that can be done about it; such is the nature of voting. There's just no real way to distinguish someone downvoting a post because they know that it's not a correct answer versus someone dowvoting for another reason.
Your description of the problem seems to line up with the second case, but just be careful and look closely. Questions that are unclear, lacking sufficient information, etc. can often look, to you, like they're very clearly asking X, when the question is actually vague enough that it could just as easily be asking about Y or Z unless it's clarified. You should be very careful in how you handle the situation to make sure that you're not actually in the first situation.