This kind http://imgur.com/4pgXFRI of building is very typical in Budapest but almost unknown in other cities (at least I do not know of any). The corridors on the outside is weird. How did this happen?
Edit: in Hungarian, I would call these "gangos ház" , gang coming from the German translation of corridor. Google images finds a number of them. The more official word is "függőfolyosós bérház" (hanging corridor house for rentals).
Originally architecture in the late 18th century was composed mostly of 1-2 story buildings oriented towards the "front" of the street, leaving the rest of the plot for carriage parking etc. As the population of Budapest started to rise by the early-mid 19th century these buildings got additional "side-wings" so more apartments could be sold or rented out. The buildings started to take on a "U" shape. After the 1848 revolution the city started to have an economic boom due to multiple factors. After signing the so called Compromise agreement in 1867 several grand projects came to realization. Firstly, the riverbed of the Tisza river was evened out in its whole length. Consequently the grain exports of the region grew exponentially. This grain needed a processing/manufacturing base, therefore mills in Budapest were constructed, which needed machines, which in turn needed workers to operate, resulting in an internal migration wave of workers moving from the eastern part of the country to Budapest. However these workers were not earning so well so they needed some cheap accomodations. The predominantly U-shaped buildings in Budapest were expanded again to fully surround the construction plot to maximize rentable apartment numbers. Mind the hungarian name "bérház". These buildings were solely made to rent all flats to low-class workers and upper-middle class families. Usually in these buildings the apartments looking at the street had the highest quality (plenty of natural light, bigger spaces, flowing water in some instances, good ventilation etc.), while the apartments in the back or on the ground floor had the cheapest prices without any commodities(dark, small, no ventillation). Most of the time two stairways were built to separate the workers from the middle-class tenants. The cheaper flats had usually a shared-toilet like in college dormitories nowadays, most of which are still used today. Just pray to God Mr. Kovács did not eat some spicy pacal before you go visit these. By the 20th century the building boom slowed down and city architects began using the "keretes beépítés" or "framework building" method, in which they combined multiple plots and built the buildings as a "framework" for a common area in the middle shared all plots. How these areas were utilized varies widely from parks to social gathering places. Sorry for the wall of text, hope it helps answering your question.
Courtyards are used to get natural light into buildings. Courtyards started leaving building designs with the invention of kerosene lamps and finally with electric light.
This world is crazy: my brother (he is an automotive researcher I had no idea he knows this stuff) pointed out these two papers have the answers, it's in Hungarian I will do a summarizing translation tomorrow if noone beats me to it: http://www.tankonyvtar.hu/en/tartalom/tamop425/0010_2A_05_Ladanyi_Sandor_Tarsadalom_es_terszerkezeti_atalakulasok/ar02.html and http://bparchiv.hu/id-341-polgarosodas_es_urbanizacio_becs_es.html
Could you post some more examples please (or tell us what they're called in Hungarian) so that we could google them?
I'm curious as well, but googling did not produce a lot of good results.