1) Has this happened to anyone else? Is this a relatively common occurrence, or am I just sloppy?
It is not very common (the usual preventive techniques include showing the draft to a few experts/friends, putting it on ArXiV, letting it lie for a month or two and then rereading it, etc. before sending it to a "top" journal) but it happens now and then. What is common is severe difficulty with finding an error in one's own work. I would say that affects more than a half of mathematicians I know. The reason is that you read not what is written but rather what you believe should be there when you just finish typing the manuscript and start proofreading. The main trick of good proofreading is to turn yourself into a complete idiot, who doesn't see a single step ahead, has no idea of the overall structure of the argument, takes everything literally, and is not convinced of anything that is not clearly put in a modus ponens form. Needless to say, it is about as hard for a shrewd person to read like that as for a genuinely stupid one to read between (or over) the lines. And even if you know all that, you are still destined to submit or even publish papers with errors. Just a few months ago, I was informed about an error in one of mine published papers. It was just a remark and the statement was actually correct, but the proof wasn't. So, to have this kind of public shame now and then is almost inevitable whether you are an unknown postdoc, or Andrew Wiles, or something in between.
I'm not sure if Poincare published a single formally correct proof in his lifetime and people still are completely puzzled by some passages in Linnik's works, so you are in a good company.
2) The anonymous referee is probably someone distinguished in my field. Do they now have a bad impression of me? (This probably is not a question that can easily be answered . . . .)
It is actually easy to answer: most likely, for him you are nobody, your name is just a random combination of letters, and your "initial value" is zero. An erratic paper leaves it this way, so nothing is lost. We are all getting worthless papers to referee every month and I challenge everyone to recall the name of the author of some bad paper he rejected 6 months ago. The only scenario in which "someone distinguished" would bother to take a mental record of your name after looking at a single opus of yours is when he finds something interesting and unusual in your work. Then your value for him is currently positive, though, of course, not as high as it would be if you solved the problem. So, again, there is absolutely nothing to worry about.
3) If I manage to patch up this paper, is it reasonable to resubmit it to this journal, or have I burned my bridges there?
Of course, it is. What matters is not how many mistakes you made on the road and who saw them but whether you finally reached your destination and whether other people consider that destination worth reaching. The theorem and its correct proof lose nothing in value if somebody published or tried to publish 20 false proofs before that. That some of those false proofs might be proposed by a person with the same name and biometrical characteristics as those of the one who finally found a correct proof changes nothing in the grand scheme of events. So, if you manage to fix the error and make sure that the argument is, indeed, correct, I see absolutely nothing wrong with submitting it again because from a purely logical standpoint, it is a different paper. If you get it returned solely on the grounds that the previous version was incorrect and not based on the merit considerations (even correct and good papers get rejected sometimes for various reasons), it'll merely tell you that the jornal is not really "top" but just "snobbish", in which case I would avoid it altogether in the future (at least, until they change the editorial board).
Best Answer
Well, of course the young mathematician should simply discuss the matter with the senior mathematician and perhaps the student until they can come to an agreeable arrangement. My advice is that they should all talk about it. Co-authorship is a matter upon which all authors must agree. What other answer could there be?
If it seemed that the professor or the student had little or no contribution, then the young mathematician should say so and inquire why the professor should be co-author, or why the student should be co-author. If there was not sufficient contribution, then the young mathematician should simply say so and there should be a discussion about it. Perhaps the senior mathematician will point out that the contribution was greater than realized, or that there were other aspects of the collaboration of which the young mathematician is not aware. Or perhaps not, and the senior mathematician will agree that the young mathematician should proceed solo.
But apart from the particular situation described in the post, let me now mention several further reactions that I have more generally to the issues about co-authorship that this question raises.
The first and most important thing to say is that collaborative research is one of the great joys of mathematical life, and I strongly recommend it. To discuss a mathematical idea with another mathematician, who can understand what you are saying and who has thought deeply about the very same topic, gives enormous satisfaction and meaning to one's life as a mathematician. Collaborative research is our mathematical social life. For my own part, I am thankful on today, Thanksgiving Day, for the opportunity that I have had to interact with all my collaborators; I have learned so much from them. (See the list of my collaborators.)
Therefore, my advice is that one should seek out collaborations wherever they are to be found. Often, after one has proved a theorem, then in joint work it becomes much better, strengthened or simplified, or a collaborator finds new applications or uses. If someone asks a question and you answer it, then perhaps the mathematics is not yet finished, but only begun. Aren't there further natural questions arising from the result or its proof? This could be the beginning of a collaboration rather than the end of one.
Another part of my view is that one should be relaxed about collaboration and co-authorship. Except in extraordinary cases, the stakes are low. A mathematician seems to get basically as much respect and credit for a result, whether or not there are co-authors on the paper, and so I question whether there really is any meaningful "dilution" as mentioned in the post. It is simply no big deal to have co-authors or not.
Therefore, why not be generous? If someone has made a contribution to your project, even when the contribution is light, then invite them as co-author. Few mathematical collaborations are perfectly balanced contributions, and in most collaborations one person has had a more important insight or made a larger contribution than the other. But so what? Perhaps the co-author invitation will be declined, and that is fine, or perhaps they will join and then proceed to make your result even better. I have had many collaborations where at first we had a result, which seemed fine and complete, but then in writing the joint paper we were able together to improve the result or give further applications, which wouldn't have happened without the joint interaction. I think you will often be surprised.
Another point, as I mentioned in the comments, is that asking a good question in my view is often sufficient for co-authorship. I have several joint papers that arose from someone asking me a question (in some cases on MathOverflow), which I answered, and then asked them to join as co-author. And I've had some the other way around as well. I find it more natural in such a case, however, for the theorem-prover to be suggesting the idea of co-authorship, rather than the question-asker, which is part of why the situation in the OP seems wrong to me.
Another point is that it sometimes happens that person A, perhaps a junior person, asks a question that person B, perhaps a senior person, answers, settling the question; but the situation is that person A simply cares more about it or has a stronger vision of what the result can become than person B, who is not as interested. In this case, the solution is that person A should do the work of writing the paper, with person B as co-author, even though the result may have been due to person B. The point is that person B would not bother to write this paper on their own, but the joint authorship brings the mathematical paper into existence. The result can be a great paper, and I know of many papers following this pattern.
In summary, pursue collaborations; be generous about co-authorship; be relaxed about co-authorship; enjoy joint mathematical interaction; make great mathematics.