Was there any widely observed prohibition on the killing of clergymen and looting of churches when a city was being sacked? To make things simple, I will limit the question to pre-reformation Europe when most kingdoms were catholic (or at least I assume so).
This is only a partial answer from my field, but in Early Medieval Ireland there was a prohibition against killing priests in warfare.
The law system which existed in Ireland before the arrival of organised Papal Christianity was a form of kin-centric civil law called the Brehon law and naturally contained no reference to priests.
When religious scholars arrived on the island in the 5th century priests and monks began to record the ancient laws, myths and histories of the Gaels.
In their recording of the law tracts they conveniently omitted any mention of the druids, who had held an important ceremonial place in Irish society, and wrote themselves into the role of religious advisors and authorities. This included a prohibition on the killing of priests during combat.
I'm assuming the main focus if your question was the later medieval periods and aimed at west/central Europe but hopefully you found this interesting anyway!
Sources: Binchy's Corpus Luris Hibernici, a translated collection of the law texts.
There is a substantial movement in the 10/11th century known as "The Peace and Truce of God." It consisted of a series of decrees promulgated by important churchmen, mainly in France, which promised divine sanction against those who committed violence against the Church or the poor, and prohibited violence on holy days. Wikipedia, for what it's worth, claims a consensus on the efficacy of the movement, but I don't believe that to be an accurate reflection of the literature, which is rather divided.
What is agreed on is the fact that the promulgation of such decrees is substantial evidence that there was lots of violence against the Church and the poor, and that there was violence on holy days, else why legislate against it?
On the other hand, I would be hesitant to tie the prohibitions against violence to something large scale, like a sacked city. In the Merovingian period, for example, we have plenty of evidence of churches or abbeys being sacked and prelates killed by what are really raiding parties. Moreover, many (all) bishops and abbots were members of the nobility, and so tied up in the intricacies of local politics and all that entailed. This is also true in the later period - in 1112, for example, the tyrannical bishop of Laon was murdered on the cathedral altar by the local populace.
Mass-slaughter of a population was fairly unusual upon the sack of the city. Two major exceptions come to mind: the sack of Jerusalem during the First Crusade, and the sack of Béziers during the Albegensian Crusade (see /u/idjet's discussion of that here). However, the fact that these are noted as exceptional events both by modern historians and historical contemporaries is indicative of how much they deviated from accepted practice.
So, for your specific question, the entire population of a sacked city was rarely put to the sword, although looting did occur. With respect to the Church, there were taboos in place, but that did not always prevent them from being violated.
Here is some further reading on the subjects I've discussed:
On medieval warfare, crusading, etc.
Riley-Smith, Jonathan. The Crusades: A Short History. 2nd ed. New Haven: Yale University Press, 2005.
Contamine, Philippe. War in the Middle Ages. New York: B. Blackwell, 1984.
On the 10-12th c. milieu, and on attempts to constrain lay violence
Southern, R. W. Western Society and the Church in the Middle Ages. Pelican History of the Church v.2. Grand Rapids: Eerdmanns, 1970.
Southern, R. W. The Making of the Middle Ages. London: Pimlico, 1993.
St. Bernard of Clarivaux. In Praise of the New Knighthood. Translated by M. Conrad Greenia. Cistercian Fathers Series 19B. Trappist: Cistercian Publications, 2000.
On Merovingian violence and martyred clergy
Fouracre, Paul, and Richard A. Gerberding. Late Merovingian France: History and Hagiography, 640-720. Manchester Medieval Sources Series. Manchester: Manchester University Press, 1996.
McNamara, Jo Ann, John E Halborg, and E. Gordon Whatley, eds. Sainted Women of the Dark Ages. Durham, N.C: Duke University Press, 1992.
On the 11/12th c. episcopate of Laon (French only)
Bur, Michel. Histoire de Laon et du Laonnois. Pays et villes de France. Toulouse: Privat, 1987.
Saint-Denis, Alain. Apogée d’une cité : Laon et le Laonnois aux XIIe et XIIIe s. Historie et archéologie médiévale. Nancy: Pr. Univers., 1994.