Randall Collins spends a significant section of The Sociology of Philosophies on why Idealism appeared where and when it did. The philosophical lineage of Kant and Hegel argues against materialism in terms that sound like a defense of the reality of God and the spiritual vision of traditional religion. Yet really, says Collins, Idealism is at best a halfway house, keeping the terms of spirit, while removing the hard-to-digest revelation and historical particularity of religion.
Collins' sociological insight is that Idealism became the dominant philosophy in universities at the very moment when they were being secularized, cutting loose from either direct church control, as in the United States, or from state church control, as in Germany and England. This holds true despite the fact that each of these countries secularized their universities in different generations -- it is not simply the zeitgeist talking. Collins' most impressive evidence is that philosophers in Japanese universities invented a Buddhist-sounding Idealism at just the moment that those institutions were separating from Buddhist control.
And within another generation, all these dominant Idealisms had been displaced by more thorough-going secularist philosophies.