Consider the medieval European priesthood... for example. It's basically where all scholarship and literacy resided. Also esoterica, healing magic, astrology, alchemy...
This persists until the scientific age. Mendel was a monk. Newton was highly devout, and mostly devoted to jewish christian protoscience... some of it tracing all the way back to those Egyptians. If you'd asked him, he would have probably described himself as an alchemist.
Recall that the church tried Galileo... because his published results negated Church dogma. That's because the study of celestial motion was a religious function. Always had been.
Ancient Greek philosophers are often seen as "proto-secular." They were mostly seperste from formal priesthood and often treated homeric gods and myth with scepticism.
But... they tended to be highly devoted to "mysteries" and their cults. There's also evidence that Socrates and co taught "secret" esoterica too... about the secret nature of the world... and triangles.
Math, religion, deciphering of celestial patterns.. those have been together for a long time.
Having religion separate from math, physics and natural science is a modern invention.