Can a university restrict publication of students' work due to plagiarism fears?
My former department had such restrictions in place prohibiting the dissemination of course work, although very little of the course work involved programming. Students signed an agreement at the beginning of every year. Further, every piece of course work required a signed cover sheet that stated that the students would not share the course work. Sharing course work was treated as academic misconduct and results in either a reduction in the students grade if the offense is discovered while the student is taking the class, a fine (talk about unethical) if the offense is discovered after the student finishes the class, or possible revocation of the degree if the offense is discovered after the student graduates.

While serving on the my department's academic misconduct committee I over saw incidents of all three types. The one case of misconduct after graduation was settled by asking the student to remove the content from the web and the student agreeing. Had they not agreed, it would have gone to a university committee. The couple of cases involving distribution after the class, but prior to graduation, were resolved with fines. In some cases the students paid, in other cases they appealed to the university committee. The university committee sometimes kept the fine and sometimes repealed the fine. The "in class" cases were sometimes appealed to the university committee, but were rarely (if ever) over turned.

As to the ethical question, our policy was reviewed annual at both the departmental level annual and the university level. It was also reviewed every couple of years by the legal department. We often discussed why the policy was so broad. In the end, we always decided that it was easier to make a broad rule and allow students to request exceptions than to try and cover all the creative ways students can cheat.