I have a request on the main meta to provide better oversight. Moderators can see a list of recent self-deletions (mod-only link), but it's cumbersome (there's no way to filter it, and a vast majority of the questions it links are unanswered). We can also search for deleted non-closed answered questions (again, mod-only link; thanks to Shog9 for the idea), which has less noise for this purpose. Unfortunately, there's no way to get alerted, but we'll try to keep an eye on it.
Given current tools, all I can say is that if you notice that an answer of yours has been deleted because the asker deleted their question, and that answer has lasting value, please flag it and moderators will undelete. (On the other hand, if the question is deleted while you were writing an answer, please repost the question in your name if you want, askers are free to delete their question, it's deleting someone else's answer as a side effect that's iffy.)
I do say if the answer has lasting value. Askers can delete their question if it is unanswered, or if it has a single answer with no upvote. The intent is to allow askers to delete questions where the answer is “you have a typo” or “you misread the problem statement”, which do not result in any teachable moment. Similarly I don't consider something like a straightforward calculation or a definition copied from a reference to be an answer with lasting value. On the other hand, if your answer can be useful to people other than the asker (and other than students doing the exact same homework assignment), I think it should be kept.
I'm proposing to make this a moderator policy: if a moderator notices a self-deleted question with an answer that has lasting value according to the guidelines above, then they will undelete the thread. Since moderators are not alerted when such deletions happen, please flag if you encounter this situation.