There’s a large body of law built up around the First Amendment rights of university professors and public employees more generally. The fact the government is an employer in some cases doesn’t override the fact that it’s still the government and largely prohibited from regulating speech except in narrow circumstances where the First Amendment doesn’t offer protections to anyone (libel, obscenity, and a few other historical exceptions) or where the speech would significantly impact the workplace or learning environment. The latter isn’t a specific test used by the courts, but that’s essentially the spirit of the case law surrounding when the government can regulate the otherwise-protected speech of its employees. For private universities, contracts or even contractual expectations created by policies regarding free speech and academic freedom (like Mayo’s policy) can place similar restrictions on the university being able to act against an employee.