- "A sinner comes before you, Cersei of House Lannister. Mother to His Grace, King Tommen, widow of His Grace, King Robert. She has committed the acts of falsehood and fornication. She has confessed her sins, and begged for forgiveness. To demonstrate her repentance, she will cast aside all pride, all artifice, and present herself as the gods made her... to you, the good people of this city. She comes before you with a solemn heart, shorn of secrets, naked before the eyes of gods and men, to make her walk of atonement."
- ―The High Sparrow to the people of King's Landing.
A walk of atonement is a public ritual of punishment and penance in the Faith of the Seven. It demands a confessed sinner to walk a certain distance stripped of all clothing, exposed to the eyes and jeers of the population.
After being caught at a brothel in the middle of a session of blasphemous sexual roleplay, the High Septon is trapped by a group of Sparrows, stripped of all his clothes and forced to walk naked through the streets of King's Landing, while one of the Sparrows publicly names him a sinner and beats his hands to keep him from covering his genitalia.
After a time imprisoned by the Faith of the Seven, Queen Cersei confesses to having committed adultery with her cousin Ser Lancel Lannister, who had joined the Faith Militant and accused her of adultery, incest, and regicide. The High Sparrow informs Cersei that she will still be tried for the other two charges that she denies while allowing her to return to the Red Keep only if she performs a walk of atonement as penance for her confessed sin. Cersei is brought to a cell where she is roughly washed and her long blonde hair is cut short. She is then is presented to the population of King's Landing so they will bear witness to her confession and penitence. She is stripped of her clothing and forced to walk completely naked from the Great Sept of Baelor to the Red Keep, escorted by members of the Faith Militant. They keep away the leering and jeering crowds who have gathered to see her shame and take the chance to insult their hated Queen Mother. As Cersei walks, Septa Unella accompanies her, repeatedly calling out "Shame!" and ringing a bell to attract people's attention and the crowd boos and pelts her with rotten fruits and vegetables. 
When King Tommen Baratheon becomes loyal to the faith, the High Sparrow tells him that his wife, Margaery Tyrell must perform a walk of atonement. He is reluctant to tell his mother, after being "counseled" by Pycelle, however he later tells Cersei. At a small council meeting, Cersei informs Olenna Tyrell that Margaery will perform her walk of atonement before the day of her trial, and they both agree this cannot happen. However, at the Standoff at the Great Sept of Baelor, House Tyrell and Jaime try to revert it. The High Sparrow then concludes that Margaery is ultimately spared from her walk, as she is already repented for her crimes, due to uncovering House Lannister's treachery against the sparrows. Tommen then agrees to an alliance with the High Sparrow, symbolizing the union of the crown and the faith.
In the books
In the A Song of Ice and Fire novels, it seems that walks of atonement are civil punishments used to publicly shame women accused of adultery or prostitution. It also serves as a means of degrading these women and stripping them of whatever pride or power they might hold. The novels mention only two people who had to go through this humiliating punishment: Tytos Lannister's mistress and Cersei.
Tywin forced his father's mistress to make a walk of atonement after Lord Tytos died. While it is common for widowed lords to take lowborn women as bedwarmers, Tytos's mistress - a woman scarcely one step above a prostitute - had come to dominate him utterly; she was seated beside him in the hall, showered with gifts and honors, and even asked for her views on matters of state. She stole from him, issued orders to the household knights, dismissed servants, and helped herself to the jewelry of the late Lady Jeyne, Tytos's wife. She grew so influential that it was said around Lannisport that any man who wished for his petition to be heard should kneel before her and speak loudly to her lap, for Lord Tytos's ear was between his lady's legs.
Lord Tytos died of a heart attack while climbing stairs to his mistress, and the first thing Tywin did on his return from King's Landing was to expel her from Casterly Rock. All the self-seekers who had named themselves her friends and cultivated her favor abandoned her. The silks and velvets Tytos had lavished on her were taken away, as was the jewelry she had appropriated. Tywin had her stripped and forced to walk naked through the streets of Lannisport to the docks for a fortnight, telling everyone she met that she was a thief and a whore. Though no man laid a hand on her, that walk spelled the end of her power. Cersei was too young to witness the spectacle herself, but heard the stories from washerwomen and guardsmen who had been there.
Although Cersei's uncle Kevan Lannister disapproved of many of her deeds (her incestuous affair with Jaime, corrupting Lancel, spoiling Joffrey, and her poor conduct as the Queen Regent), he does not gloat at Cersei, but feels sorry for her public humiliation. He muses sadly that Tywin would have never dreamed that the same degrading punishment he gave their father's mistress would be imposed on his own daughter.
In the novels, when Cersei is shorn, the septas remove all of her body hair - her eyebrows, pubic hair, even scraping the rest of her body. They shave her head completely bald. In the TV episode, the septas prominently produce a razor blade as if they are going to shave her, but curiously does not use it at all. One septa separately picks up a pair of shears, and cuts Cersei's luxurious long golden hair off - but crops it close to her head, instead of shaving her bald entirely. In her subsequent nude scenes the rest of her body hair isn't shaved.
While Cersei performs the walk of atonement, she hallucinates many characters, most of them are long dead, standing among the crowd: her father, frowning; Melara Hetherspoon, Ned Stark, Sansa and Lady stare at her accusingly; Tyrion, jeering at her; Joffrey, smiling sweetly; and finally Maggy, hissing her prophecy about another queen who will cast Cersei down.
George R.R. Martin has stated that Cersei's walk of atonement is loosely based on what happened to Jane Shore, the mistress of King Edward IV of England. Like Robert Baratheon, Edward was a great warrior who won the crown on the battlefield in his youth, but became fat and ill-suited to rule in later life. After Edward died, his brother Richard III usurped the throne ahead of Edward's sons. He deeply resented Jane, so he had her arrested and made her perform a penance walk, a common punishment for harlotry. Jane did not perform the penance walk naked, however, but had to walk barefoot through the streets of London wearing only her kirtle (petticoat), which at the time was still said to have gained significant male attention (the main source of the humiliation was that this was a punishment normally meted out to harlots). Martin has said that the Wars of the Roses were one of the major inspirations for his novels: the conflict was between the Yorks and Lancasters, while in Westeros the conflict is between the Starks and Lannisters (clearly named after the real families).