Sometimes we do lose, and that's just part of life. We can minimise our losses by recognizing question askers likely to pull a BS move like this.
These people typically ask very low quality questions. Questions where they haven't bothered debugging, or where they haven't done any research on their own. Your answer may embarrass them, so they delete as soon as they realize their stupid mistake.
Another big red flag are users who don't spend any time asking a well-formed question. Have they littered their questions with cheezburgerspeak? Ur can haz 2 b carefuls of deez fokes. Have they spent more than a second making sure their code is formatted correctly? Have they crapped out a big block of text, or have they formatted their question well? Do they give you the impression that they haven't spent more than the absolute minimum amount of time to create the question? If so, be leery, as they have already demonstrated that they don't, at a minimum, care about the community.
And stay far away from people who post off topic questions. You can spend a good deal of time answering them only to have the community downvote, close and delete it. You waste your time feeding these people information, just as they waste our time vomiting off topic questions everywhere.
Just keep your head about you and be reluctant to spend time helping people who refuse to spend time asking a decent question, and you'll find you get screwed over this way rarely, if at all.