I think I see. Howerver, "carried out" is basically how you see "学校の役割をしていた。" correct? I think perhaps it is confusing to me due to the use of two nouns and "をしていた。" because apparently I don't come across that often in my studies.
Ok, to add to Undrentide's post:
first off, do you have a problem understanding the phrase 役割をする? For the time being, I will assume that it's not a problem. (Correct me if this assumption is wrong.
)
So then, I also assume you understand していた by its own. (Again, correct me if I'm wrong!)
So put the two together and you have 役割をしていた。 Just a note here on tenses in Japanese versus English: in English there are several ways to render this translation depending where you want to place the emphasis, but for argument's sake, let's look at Undrentide's translation (because it is more literal to the Japanese than mine).
With this translation, we would probably say "played the role" rather than "was playing the role" because in English, the idea that the part was played continuously for a long period of time can be conveyed in the simple past with this particular phrase, but for Japanese the rules are different. To convey this idea of something happening continuously for a period of time in Japanese, we need the past progressive tense. Otherwise it becomes a one-time occurance.
Anyway, back to the subject at hand, at this point we have 役割をしていた。 The English would be "played the part". Next, we add WHAT part was being played, namely that of school
学校の役割をしていた。 ([It] played the part of school.)
Next we add the subject. Who or what played the role?
寺院などが学校の役割をしていた。 (Temples and the like played the role of school.)
Let's add spaces to show where the main sentence components begin and end.
寺院などが 学校の役割を していた。
Remember that in Japanese, the order Subject-Object-Verb is not as strict as the SVO order is in English. It is possible to turn SOV order into OSV order without any loss of grammaticality. (I think I just invented a new word!
)
So let's do that and reverse the subject and object in our sentence.
学校の役割を 寺院などが していた。
Take out the spaces, and we have the main part of your sentence.
学校の役割を寺院などがしていた。