Can an advisor write a student's PhD thesis? I've recently discovered a strange situation.  A few years ago, a senior mathematician published a certain solo paper X.  A few years prior to that, one of his students wrote a thesis Y on the same topic, and large parts of paper X are copied verbatim from thesis Y.  In the thesis, it is indicated that the work is intended to be a joint publication between the author and the student, however neither the student's name nor the thesis are mentioned in paper X.

Note: I am not concerned about the general issue of duplicating material from a thesis in journal papers (this seems to be considered acceptable, e.g., How much overlap is permitted between a submitted journal article and a thesis? and How to avoid self-plagiarism when adapting dissertation into a paper?), but here the authors of X and Y are different.

This suggests some possibilities, none all that great:


the advisor plagiarized the student's thesis 
the advisor didn't plagiarize the student, because the advisor actually wrote the thesis, and later decided the student didn't deserve co-authorship
the advisor and the student wrote the thesis together, but the advisor just claimed sole authorship (I believe the student left academia)


I know the advisor was working on this project before, so I suspect one of the latter two is closest to reality.  I certainly thing something about this situation is wrong, but I don't know the details of what, so my question is:


  To what extent is it acceptable for a student's advisor to physically write their PhD thesis?  


I know sandwich theses are okay (depending on school), and in many areas theses comprise joint papers.  So I suppose it happens that in certain fields, that a student might not write any of their "thesis", except the introduction.  (In this case the introduction was copied also, but that's beside the point of this question.)  

Note: In math, it is rare that the whole of a student's thesis work is published jointly with their advisor, even if the advisor did a lot of the work.  However, in math my personal expectation is that thesis should largely be written by the student; even if an advisor does most of the work for the thesis, it should be largely written by the student.  I'm interested in an answer for both math and non-math PhD theses, if there's a difference.
The salient point here is that a PhD thesis is supposed to be the student's work. What primarily matters both for appropriateness of the degree and issues of plagiarism is whose work it is, not who typed it into the computer.

Usually the student is the one expected to do most of the writing, and if they are not, I would probably consider it a red flag. But I could imagine circumstances where this might be entirely appropriate. For example, perhaps a student did the work but is unable to write it up due to a physical handicap or a mental condition that makes writing difficult.  I don't think it would be considered inappropriate for someone else to do the bulk of the writing--directed by the student concerning content--in such a case.

The situation you describe is indeed problematic. Even if the professor wrote every word of the thesis, it would be inappropriate to omit attribution unless the student literally contributed nothing to their own PhD project.

Either the student's PhD was not legitimate or the professor is plagiarizing the student. Quite possibly both.

Note: since you described extensive copying in a paper on the same topic, I'm assuming the copied text is a substantive part of the thesis. It would be somewhat different if the copied material is just something like background info shared between both. Though omitting a reference seems inadvisable in any case, it would be a much smaller issue.

Note 2: just to clarify, this is a general answer. I don't have any academic experience in mathematics.