The name Porto is pronounced
/'portʊ/ (closed o), but portas is pronounced
/'pɔrtɐʃ/ (open o). Why? Is there any specific rule for this behavior?
The name Porto is pronounced
It seems your question has been discussed by experts in the language several times... The issue here is the "vogal aberta" (open vowel) vs the "vogal fechada" (closed vowel).
The answer is, to put it simply and bluntly: there is no consistent rule for the o in "Porto" to be closed and "porta" to be open, they are pronounced the way they are because the sound stuck like that throughout the centuries.
In the link provided by bfavaretto, the relevant part is:
Because it is an unmarked phenomenon, the use of umlauts become extremely difficult for students that have never before had contact with the Portuguese language.
There are cases like forno, in Latin [i.l.] furnǔm, miolo i.l. pǔteum, miolo i.l. medǔllum, formoso i.l formosum, where (ǔ) and (ō) in Latin are open in the feminine and in the plural by analogy, that is, by a linguistic change process consisting in changing morphs in order to fit an existing model. In these cases, there is an open vowel antietimologicamente [I presume this word means antimorphologically] that meets the singular masculine scheme with a closed o and the plural masculine and the feminine and masculine singular and plural with an open o, such as in fornos, poços, poças, miolos, gostosa and gostosos.
There are instances where the formation of the feminine and plural remains faithful to the etymology and, therefore, does not adhere to the analogy process. Such an occurrence is perceptible in words like lobo [wolf] i.l. lǔpum, gosto [to like] i.l. gǔstum, esposo [groom] i.l. spōnsum, which in the respective feminine and plural remain with a closed o, i.e. lobas, lobos, gostos, esposa, esposos.
The important part to retain in this is Porto has the closed o due to being faithful to its etymology.
Therefore Porto is kind of the rule breaker because in the old times people used a closed o when pronouncing it... And you can tell this because, portos has an open vowel (unlike lobos) which is consistent even with the English word ports and port (both with an open vowel).
Furthermore, in ciberduvidas they explain the following:
The list of plurals with an open o (as in almoços and poços) will always increase, and there are always a few words whose plural oscillates between ô [Porto sound] and ó [Porta sound], until it ends, analogously, with the open vowel being imposed. The list made by of our biggest phonetician, Gonçalves Viana, is already much smaller than the current one, and in the life of a person, there are numerous cases where changes like these happen.
And there are errors, of course, by pseudo-scholasticism. So molho (in cooking) keeps a closed o in the plural, but some careless people "open" it, because they refer to a specific sauce (green vegetable sauce) and its plural, both getting the open o (i.e. mɔlho and mɔlhos).
This [issue] would give a treaty; so sorry for not dwelling into more details.
The conclusion is that, old closed vowels are prone to become open vowels.
So probably someday someone will say "É o Pórto!" and people around listening will flinch and some will say, "Não! Diz-se Pôrto carago!!!", but at the end of the day, they knew exactly what you were referring to (and they won't give a flying carago about it;).