Q:

How am I supposed to answer the wrong question? 

Every now and then a very leading and/or a overly specific question gets asked.  Note that this doesn't make the question bad nor a bad fit for our site.  
There are two ways for us, as answer-ers, to deal with this:

Answer the question verbatim. 
Address the underlying issue. 

I often strive to do the second method, but sometimes my inner ass wants to do the first, and succeeds.  
Which method am I supposed to use?  The one that needs my superb mind reading skills* or the one that is asked but leads to the wrong conclusion? 
* Sorry, Scott it's possible, just very error prone ;) Yeah, my mind-reading skills suck anyway.  

A:

As I've stated in a comment, your question reminds me of this post about the XY problem on Meta. 
I would suggest you could answer the question and address the underlying issue.  Ideally in discrete parts so that it's easy to make sense of for the reader.   
Worst case scenario, your mind reading skills were off and the asker ignores or is frustrated by that part of your answer.  Best case scenario, you went above and beyond to help someone help themselves.  In my experience, it can be incredibly enlightening when someone helps you see the bigger picture and where you've taken a wrong tangent. 
The problem with doing both is that it's more time consuming, and that the asker themselves may not understand the other underlying issue that is so blatant to you, so you might be wasting your time.  Depending on the question, another option could also be to suggest the user joins you in chat to discuss what their issue actually could be. 

A:

Why not do both options? 

I would say that sometimes you can post them as their own answers, as I did here, with this answer. 
I answered the OP's question and then realized that this whole problem could've been solved had the user created it differently, so I posted a 2nd answer (which they ended up accepting)
However, as far as their actual issue, my first answer was still a valid (and correct) to answer their question, my 2nd one just helped them the most. 
I normally would just add it to the answer, but since this was a drastic change, I just made it separate.