I've heard people talk about Aztecs, Incas, Mayans, and other New World civilizations using "magic mushrooms" in religious rituals. But I don't know how true that is. So first, do we know for sure that any of them used mushrooms containing psilocybin for any religious use? And if they did, do we know anything about their use, and religious significance to them?
Oh yes. And not just mushrooms; there were a whole suite of hallucinogenic drugs that the civilizations of the New World used as sacraments. Magic mushrooms (Psilocybin mexicana) were common among the Aztecs and other Central Mexican groups. Peyote was used in both Central/Northern Mexico, the American Southwest, and among the Maya. Salvia comes from Oaxaca and was used by cultures in that region. The hallucinogenic San Pedro cactus was used by the Andean cultures of South America like the Inca. There were also seeds from a plant the Aztecs called ololiuhqui that could induce hallucinations. There was a species of water lily used by the Maya as a hallucinogen. There is even a species of toad in Central America called Rhinella marina that emits a hallucinogenic toxin when stressed. If you lick it while it's secreting this toxin, you will hallucinate - and it appears that the Maya and other neighboring groups did this. There are likely even more such drugs that we're not familiar with - "snuffing pipes" for nasal delivery of drugs have been found in the Mexican state of Guerrero.
The use of hallucinogens is tied with a suite of spiritual practices that anthropologists often call "Shamanism." In a nutshell, a lord or priest (or "shaman" in this context) derived spiritual power from the perceived ability to move between the physical, mortal world and a supernatural world. A shaman functioned as an intermediary between humans and the supernatural. My favorite description of this comes from the Q'uiche' Maya of highland Guatemala. Their creation story, known as the Popol Vuh, describes how during the early days of creation humans had the ability to perceive gods in the same way that gods could perceive people. However, the gods did not want humans to be able to see them, so they obscured the divine world "like fog on a mirror." To borrow their metaphor, hallucinogenic drugs let a person pierce the fog and perceive the divine.
As to the specific rituals they were used for, we have records of their use in divination rituals as well as major religious events like the coronation of a new ruler. Duran describes this incident following the coronation of the Aztec emperor Motecuhzoma II:
They all went to eat raw mushrooms; on which food they all went out of their minds, worse then if they had drunk much wine. With the force of those mushrooms, they would see visions and have revelations of the future.
And here he is describing the coronation of Tizoc:
They all ate some woodland mushrooms, which they say makes you lose all your senses, and thus they sallied forth for the dance.
The Maya also appear to have taken hallucinogenic drugs such as peyote in the form of enimas, as shown in this hilarious yet mildly NSFW ceramic sculpture. Similar motifs can be found painted on pottery like this example.
Consumption primarily took place within the confines of religious ritual. There also appears to have been some recreational use of hallucinogenic drugs, although this was frowned upon. From Sahagun, p. 37 (referencing the cultural taboos of the Aztecs):
The Lewd Youth is a drunkard, foolish, dejected; a drunk, a sot. He goes about eating mushrooms.
Peter Furst has repeatedly claimed that certain elements on the shaft tomb figures of West Mexico are related to shamanism. His work with the Huichol and their use with peyote had convinced that people in the same region were doing similar practices or at the very least consuming peyote. The most common element that Furst claims to be a shaman feature is a horn strapped to the forehead of some of the figures, which I will admit is a little odd. His claims however seem stretched for other types of figures like those of the warriors who carry a spear and wear barrel shaped armor and some sort of helmet protecting their head that does not include the horn element.
Furst, Peter
1965 Shaft Tombs, Shell Trumpets, and Shamanism: A Culture-Historical Approach to Problems in West Mexican Archaeology. Unpublished Ph.D. Dissertation, University of California at Los Angeles.
1998 Shamanic Symbolism, Transformation, and Deities in West Mexican Funerary Art. In Ancient West Mexico. Art of the Unknown Past, edited by Richard F. Townsend, pp. 169-190. Art Institute of Chicago, Chicago.
If you are interested in more information on the plants and some of their practices you should read Plants of Gods. It also has information about other cultures and plants uses around the world.