These fences are called inu-yarai, and their name suggests (inu means "dog") that they were originally designed to stop the dogs from soiling the walls. Other possible purpose was to protect the walls during the rainy season against the dirty water on the road... But whatever their original function was, they are today an original feature, nicely embellishing the buildings.
EXIF info:
Nikon Df
Lens: 24-70mm F/2.8G
Focal Length: 27mm
Aperture: F/3.5
Shutter Speed: 1/60s
ISO Sensitivity: ISO 8000