An answer of mine was recently deleted because it was decided AFTER my answer was posted and accepted that the question was off topic. I thought putting a question on hold simply prevented any further answers from being posted. By why delete an answer already accepted before the on hold decision was made. I have answered other questions that were subsequently put on hold, but it did not result in deletion of my already posted answer. This is very frustrating.
The very last comment by @DavidZ is self-explanatory and absolutely appropriate:
I'm temporarily deleting this in accordance with our homework policy. Please don't post complete answers to the underlying problem in homework-like questions.
Zero's already explained the bulk of it, but it's worth drilling down a bit:
Your answer was removed because it is considered by the community to be harmful to the site.
This is explained in depth in the meta thread that explains the homework policy and which is linked in the closure banner of the question. This is the kind of guidance that we expect experienced users to read before coming to meta with complaints.
The question you answered is absolutely terrible, and its presence (and that of other questions like it) on the site accomplishes two things: to make this site look like a dump of undigested homework questions where lazy students can get others to do their work for them, and then, because of that, to make it much harder for this site to retain expert users who can answer the truly valuable questions.
By giving that user the complete answer that they wanted, you just encouraged them (and any friends that they might talk with) to post similar questions in the future. This is why those answers are routinely removed on sight by the moderators, as stated explicitly in the site policy that's always linked on homework-closed questions.