Sigmund Freud said this quote

I can imagine that the oceanic feeling could become connected with religion later on. That feeling of oneness with the universe which is its ideational content sounds very like a first attempt at the consolations of religion, like another way taken by the ego of denying the dangers it sees threatening it in the external world.