Naming a library or program partially after a school
Berkeley and Stanford are places, not - institutes. So I guess no permission is needed (unless from the respective mayors). (However, my guess might be wildly wrong for the US law.)

See also https://perso.uclouvain.be/vincent.blondel/research/louvain.html:


  is now known as the "Louvain method" because [...] the method was devised when they all were at the Université catholique de Louvain.


When one wants to use an institute's name (e.g. "MIT", as in one of your examples) - at least an informal consent may be needed. (But in some places rules may be much stricter - and it is impossible to make a general answer.)