Those walls were built in the Renaissance period when the Pope reigned over a country in Central Italy and regularly fought wars with other Italian states. So they needed walls in order to resist in case of siege.