One theory of theatre is that it grew out of rituals that were religious in nature. Even if we think of modern day religion, there are may ritual aspects that might be considered "theatrical" such as the specific positioning of a body to assist in prayer or the recitation of particular words being imbued with particular significance.
Many of the earliest pieces of "theatre" that have been preserved have a religious component. One example is the Egyptian "Abydos passion play" which was performed by masked priests who acted out the story of the death and resurrection of the Egyptian god Osiris. The ancient Greek plays we read today grew out of Greek religious choral traditions and were performed at yearly festivals honoring the Greek god Dionysus. Japanese Noh theatre combines music, acting, and dance to attempt to communicate Buddhist themes.
In Medieval Europe, many people could not read, and would turn to dramatic presentations of biblical stories to understand Christianity. Some of these presentations, such as passion plays at Easter (showing the suffering of Christ during his crucifixion) or nativity plays during Christmas (showing the story of the birth of Christ), are continued to this days. Another form of medieval religious theatre were play-cycles, in which many biblical stories would be performed by different groups, each after the other. Learned scholars who had the ability to write, such as the nun Hrotsvitha of Gandersheim, would also write their own plays dramatizing christian virtues.
Later, humanist writers in the Renaissance would find inspiration in biblical tales and would write so-called "biblical tragedies" which often depicted biblical characters and situations as analogues for pressing concerns of the moment. Equally however, religion has sometimes been in opposition to theatre. The English Puritans were famously opposed to theater and succeeded in having theaters closed in England throughout the seventeenth century.