The primary function of shrines is to allow units to promote to higher classes once they have reached the appropriate level to do so. Aside from giving access to promotions, shrines serve other purposes as well. In Echoes, you can offer up a food item to the Mila Statue in the shrine to cure the party's fatigue, and restore uses to Mila's Turnwheel. As fatigue is cured and the Turnwheel is restored to full capacity upon returning to the world map, this should only be done during long dungeon treks. You can also view a log of previously-seen Support conversations, watch Memory Prisms, and activate amiibo here via the "Turnwheel" menu, though that can be done on the world map as well.
In general, the player must traverse a dungeon filled with enemies to get to a shrine, though some towns feature shrines that you can use without the need for combat. Shrines are explored in the same manner as towns are, and may contain items to obtain or people to talk to.
In addition, shrines are often also home to Lion Head Statues, fountains that run with water that can provide a limited number of permanent stat boosts to your units. Which stat is boosted and the number of uses you get varies depending on which fountain it is. In Gaiden, the fountains are usually present in the same room as the shrine itself, while in Echoes, they are in a room behind the shrine. Some fountains can also be found in the middle of dungeons, not just at the shrines.
In Echoes, there are special DLC Shrines that can be visited to access Overclasses. In order to overclass, characters must reach Level 20 in their promoted class.