This is in fact a sort of Zeugma (conglomeration of words that won't fit well), like in
Er schlug die Scheibe und den Weg nach Hause ein.
Ich heiße Heinz Erhardt und sie herzlich willkommen.
"Große und Hauptstadt Berlin" or "bayrische und Bierstadt München" would be of the same form, but barely acceptable by native speakers. The only reason why Hamburg (i guess) still carries that title (with pride) is it's long-standing tradition and it's traceability to the middle ages, back when lower German (Niederdeutsch) was spoken ("Friee un Hansestadt Hamborg"). I can only assume it was acceptable in lower German and was carried on to Hochdeutsch.
It's interesting to note that Bremen, with a very similar history in the same region, carries the slightly different title "Freie Hansestadt Bremen", which means the same but is completely grammatical.
In case you're asking for the "frei" - This was a specific city privilege from the middle ages for large or specifically wealthy cities that were independent from the local souvereign, and rather direct subordinates of the German Emperor.