Can an advisor write a student's PhD thesis?
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.