Firstly, lets start off by saying that there was nothing wrong with your action(s) of answering the question at the point you did. We, as users, are not expected to look at a question's history and see that the context of it has not just been changed significantly (such as in the event of an XY Problem) but that it has been changed completely with no overlap at all.
The real problem stems from several things:
- The OP of the question (in question) completely changed the context of the question.
- Bountied said question immediately (2 minutes 37 seconds) after the edit was made.
- Another user in the community rolled back the edit without considering that an answer to the new™ question had been posted.
Point 1:
Generally such actions are frowned upon. Questions can be edited to add more context, or even correct the goal posts based on the comments (such as in the aforementioned XY Problem scenario), but this should certainly not be done after answers are received. No answers, however, had been received at the point of the complete context change, so many of the "standards" the community apply to such edits don't apply.
As has been mentioned in the comments, Jean-François Fabre's answer however, touches on this well; they explain that really the question can only be completely amended in the minutes after it has been posted and only if it has had no interactions. If there have been interactions this poses issues on things like comments.
If the user isn't question banned, then they should have posted a new question and waited to bounty it when they were allowed to; if that was their actions I do feel that there actions were in "the wrong".
If, however, they are questions banned then I think the OP would have been best here the flag the comments on the question as "no longer needed", wait for them to be deleted, and then completely edit; so as not to cause said confusion.
Point 2
This I think was wrong. There is a reason that new questions aren't allowed to be bountied straight away, and the edit made the question a new™ question. There's no way to stop the user from bountying it, but I feel it is "underhanded". I would suggest that someone who noticed the complete context change edit (the person in point 3) should have flagged the question to perhaps have the bounty removed.
Point 3
These actions were certainly wrong, as it invalidated an answer; these are "higher class citizens" that comments, and take priority, even if the answer is newer. Unfortunately I don't feel that rolling back to the complete edit is now correct, as an unfortunate chain of events has occurred that (in my opinion) puts means states of the question are "invalid". What should have happened here is what I said in point 2: the user should have flagged the question, not just rolled it back.
What happens now?
From us users? Nothing. We can't, I don't feel, solve this problem now. Like I said, I feel both states are "invalid". The old question has relevance for the comments, and (like mentioned) generally changing a question like this is frowned upon. The new™ question, however, is valid for your answer, so should also be there.
Only a moderator can really solve this problem now. I, personally, have flagged the question, citing this question in said flag, and I am sure others have to. If the user isn't banned, I would expect the moderator to tell them to use the new question "feature". If they aren't then perhaps advise them to get the question cleaned up first. The person that did the rollback should also be reminded to not perform them in such a scenario and flag for moderator attention.
I would guess, however, that the end result will be the bounty removed, comments cleaned up, and the question reverted to the one you answered. That is the cleanest solution in my opinion.