I wonder whether there is any university that requires students to release their source code (or at least part of it) in order to obtain their PhD.
Note: My answer pertains to schools in the US.
Does any university require students to release their source code in order to graduate?
It depends on what you mean by "university." That is, I think there are fundamentally two different interpretations of your question. Since OP has not yet provided clarification, here goes ...
If what you want to know is:
Are there dissertation committees which require students to release their source code in order to obtain approval of their dissertation?
The answer to this variant of the question is yes, this is fairly common in the engineering departments I am familiar with. Typically what is done if source code is required by the dissertation committee is that it is included in the dissertation appendix. Other alternatives include placing the source code online and citing it in the dissertation (e.g., placing the code on GitHub).
If, on the other hand, what you want to know is:
Are there universities which adopt a university-wide requirement for students to release their source code in order to obtain approval of their dissertation?
The answer to this variant is (most likely) no.
There's a much broader issue here having to do with copyright and patent rights on student thesis work. Laws vary from country to country. Within a single country, different universities may have different policies and even within a university a particular project might be funded by an external contract or grant that has further restrictions. Thus there's no completely general answer.
To the extent that students make use of university facilities and are paid by the university, and to the extent that the student's work is actually developed jointly by the student and the academic advisor, the university has some basis for claiming ownership of this "intellectual property."
Intellectual property is an all-encompassing term for patents, copyrights, and even trademarks, but the law governing each of these is very different, and using this term can easily lead to confusion. Administrators who use the term tend to be focused on giving the university as much control over intellectual property as possible and often use the phrase in ways that imply this control even when its not warranted. Thus it's a good idea to be more specific in talking about the different kinds of intellectual property.
Many universities have policies and explicit agreements about intellectual property that students are required to sign before they can begin work on research projects. Furthermore, if the student is funded by a research grant or contract they may have to agree to additional conditions. For grant funded research its not at all unusual for the grant to promise that all software developed will be open source, while for industry funded research it's not at all uncommon to have a requirement that copyright will be held by the funding organization (and the software will be kept proprietary.)
Some examples of policies on intellectual property that effect graduate students:
University of Wisconsin-Madison: https://research.wisc.edu/projectagreementsip/intellectualprop/
It's also possible that the academic advisor will set requirements for publication of the software as a condition for agreeing to advise the student on a dissertation or thesis. For example, my practice is that at the start of an MS thesis or PhD Dissertation, I require the student to agree that software they develop in the project will be made available on an open source basis. If the student is unwilling to agree to this, then I may be unwilling to supervise the thesis. It's important that there be agreement on this before the project starts.
Even in the simplest case where the student's dissertation is simply a written document describing the research there can be intellectual property issues. Dissertations are traditionally "published" by the university in the sense that bound copies are placed in the library and made available to anyone who wants to borrow them. Many universities now publish dissertations electronically through their own repositories or through services like Proquest. In order to publish a dissertation in this way, the university has to require the student to give copyright permission (but not necessarily transfer the ownership of the copyright to the university.) The most common policy in this area is that the student owns the copyright to the dissertation but must license it to the university for publication and that this is a condition for receiving the degree.
To answer the OP's specific question, I'm not aware of any university that has a general policy that all software developed as part of a PhD dissertation or MS thesis must be "released" (as open source software) However, many universities have policies that say that the university owns the intellectual property and they could demand that the student give the software to the university and then release the software as open source software if they wanted to. This could also be required under the conditions of a research contract or grant, and it could simply be a requirement of the thesis advisor.