A funeral is a ceremony to honor and pay respect to a person who has recently died, and typically involves arrangements for their corpse. Funerary customs are closely tied to religious beliefs and practices. Specific funerary practices vary throughout the known world, and can even vary within regions that follow the same religion.
Burial is the predominant method used in Westeros, by both followers of the Old Gods of the Forest and the Faith of the Seven, though cremation is practiced in certain locations. Meanwhile, cremation seems to be somewhat more common in parts of Essos, though burial is also practiced. The ancient Valyrians, (apparently) the Lord of Light religion, and the Dothraki all burn their dead on funeral pyres.
Faith of the Seven
In the Seven Kingdoms, the bodies of the dead are tended and prepared by the Silent Sisters, a religious order within the Faith of the Seven devoted to this task. Their monastic order is sworn to service of the Stranger, the aspect of the godhead that represents death and the unknown.
The body of the deceased is usually laid in state for visitors and prayers. The body is displayed atop an altar, changed into formal clothes (and if they died violently, their wounds cleaned up as best as possible). The body's hands are clasped together over the chest, and men's bodies are often laid in state with their hands clasping a sword (pointed down). In septs which are large enough to have statues of each of the Seven in a ring around the main chamber, such as the Great Sept of Baelor, the body itself is positioned so that the head is pointed towards the statue of the Stranger.
Two funeral stones are also placed over the closed eyes of the deceased, each painted to resemble open eyes. The symbolic meaning of this is to remind the faithful that they should not fear death, because it is not truly the end: we close our eyes in this world, but our eyes open again in the afterlife.
Wealthy adherents such as members of the nobility can afford to have their corpses embalmed, to slow the processes of decay while they are entombed. This process involves removing several internal organs from the corpse, the ones that break down most quickly, and placing them in seven ceremonial vases - which are then placed near the corpse at the funeral ceremony itself (often at their feet).
There can be some variation in the Faith's funeral practices, however, even between individual noble Houses, and some traditionally practice cremation. House Tully of Riverrun is a very prominent example, as seen at Hoster Tully's funeral. The corpse itself is prepared and laid in state much as at a typical funeral, with the eye stones and seven vases, but it is then ceremonially set adrift on the Red Fork of the Trident River, in a small boat filled with straw, wood, and oil. Afterwards a member of the funeral party shoots a flaming arrow at the boat from the shore, setting it aflame, and thus cremating the corpse. The Trident River waters the lands of House Tully and sustains the lives of its people - life comes from the river, and returns to it. It is unclear if all or even most Houses in the Riverlands also practice funeral boat cremations like House Tully does.
More generally, followers of the Faith of the Seven will sometimes resort to cremation if circumstances prevent them from conducting a more thorough burial, i.e. if they are on military campaign and the ground is too stony to dig, or if there are too many corpses to dig graves for, such as after major battles or in times of plague.
Members of House Targaryen, despite converting to the Faith of the Seven after conquering and uniting the Seven Kingdoms, continued to practice cremation in the tradition of their Valyrian ancestors. As the royal family of the Seven Kingdoms, the ashes of members of House Targaryen were interred at the Great Sept of Baelor in King's Landing. Following the fall of the Targaryen dynasty, the new royal family was expected to follow in their footsteps by having their dead entombed in the Great Sept's crypts (though not cremated). King Robert Baratheon, however, demanded that his remains be sent to his family's ancestral seat, Storm's End, to be interred with his forefathers (possibly also because he hated the Targaryens and didn't want his final resting place to be alongside them).
Valuable servants of the crown sometimes may also be deemed worthy of being interred at the Great Sept as well. Grand Maester Pycelle expressed his hope that he would live out a long life and at the end of it peacefully rot away in the crypts under the Great Sept.
Old Gods of the Forest
Descendants of the First Men who continue to worship the Old Gods of the Forest generally seem to prefer to bury their dead. Members of wealthy noble Houses are often buried in extensive tombs. Little is known about the funeral ceremony itself in their religion, but like their marriage customs they are probably much more simple than those in the Faith of the Seven.
House Stark, for example, buried their dead in an extensive system of crypts underneath their castle-seat at Winterfell. Each individual tomb has a stone sculpture placed above it in the likeness of the deceased. The tombs of Stark men are often left with real swords held by their statues. The Starks have ruled over the North for so many thousands of years that the crypts underneath Winterfell are truly vast, some say as large as the castle above.
The other Northmen also seem to predominately bury their dead, often in large tombs, some of which are located under large artificial burial mounds (barrows). The North is dotted with many ancient barrows, some thousands of years old and their owners forgotten - as evidenced by place-names such as the Barrowton in the Barrowlands, the southwest of the North which is noted for its large concentration of barrows.
There is still some variation from one House to the next in the North, a few of which practice cremation. Deceased members of House Forrester are placed on an ironwood casket, with ironwood tree seeds in their palms. Their pyres are then burned, emitting the rare blue flame from the ironwood, that is said to only burn for Forresters.
The Free Folk who live Beyond the Wall, derisively known as "wildlings", also follow the Old Gods - but apparently, all of them now burn their dead. By the War of the Five Kings, the wildlings cremate their dead due to the accurate fear that the returning White Walkers can resurrect corpses as undead wights. As with the Northmen, the funeral isn't conducted with much ceremony - and in this case seems to be much more about simply disposing of the body. It is unclear if the wildlings practiced cremation centuries ago, before the return of the White Walkers, or if they always did out of a cultural fear of them which continued to be held for thousands of years. Either way, the wildlings do not possess much in the way of skill or resources with stonework to make tombs like the Starks did.
The Night's Watch
The Night's Watch burn the bodies of their fallen members in funeral pyres. During the ceremony, the highest ranking member present gives a eulogy for the deceased black brother. He finishes the eulogy with the traditional line, "and now his watch is ended", which is then repeated by the gathered audience. The line refers to the sacred vow of the Night's Watch that a member's watch will not end until his death.
The Watch apparently holds this non-denominational funeral custom for its members regardless of what their personal religion was, though given that none of the three major religions in Westeros have a prohibition against cremation this doesn't seem to be an issue.
It seems probable that the Watch's tradition of burning its dead is a holdover from the Long Night thousands of years ago, and that like the wildlings they burn their dead to prevent their corpses from ever being turned into wights - though it is unclear if in generations prior to the War of the Five Kings, they remembered that this was the original reason why they practice cremation.
Maester Aemon was born a member of House Targaryen, before later joining the maesters and then the Night's Watch. His body was burned on a funeral pyre at his funeral, as was fitting not only for a member of the Watch but for one of the Targaryen bloodline.
There are many more numerous and more diverse religions and cultures in Essos than in Westeros, which probably have similarly diverse funeral customs.
The ancient Valyrians burned their dead, often with dragon-fire. The Lord of Light religion, the most widespread religion across the Free Cities and several other regions (particularly the southern Free Cities), probably also practices cremation.
The Dothraki mounted hordes (khalasars) from the plains of central Essos also burn their dead on funeral pyres. The Dothraki believe that the stars in the night sky are the fiery khalasar of the Great Stallion (the horse god which is their primary deity). Burning a Dothraki's body allows his ashes to rise up to the heavens, where his spirit will join the fiery khalasar of the Great Stallion, and ride with the spirit of his ancestors in the Night Lands (afterlife).  It is considered a terrible dishonor not to burn a dead Dothraki. The prospect of insects and worms eating through their corpse until it decomposes to nothing but bones is considered quite horrifying to them.
Desecrating a corpse by denying it proper burial is considered a heinous offense in every major religion and culture, even if the dead person did not follow the same religion.
Sometimes a corpse can be desecrated simply by denying it a proper funeral, but simply leaving it unburied in the wild to rot and for wild animals to scavenge.
In more extreme cases, a corpse may be terribly desecrated by mutilating or dismembering it after death.
Putting an executed person's head on a spike for public display is not, strictly speaking, considered an act of desecration: with the medieval-level of information technology in Westeros and Essos, putting a head on display is often simply meant to confirm to the public that the executed person is in fact dead. Needlessly harming the body more than that is considered improper, as is leaving a head on a spike until it rots to pieces - long after the point of confirming his death has already been made.
Several notable desecrations include:
- Robb Stark's body was horrifically mutilated after he was killed in the betrayal at the Red Wedding. His head was cut off and the head of his direwolf Grey Wind was crudely sewn in its place by the Freys, who had already violated sacred guest right by betraying Robb while he was a formal guest at their castle, the Twins (though while Frey crossbowmen severely injured Robb, it was Roose Bolton who dealt the death blow when he stabbed him through the heart). The Freys then triumphantly paraded Robb Stark's horrifically mutilated corpse are their castle on a horse while mockingly chanting, "King in the North! Here he comes, the King in the North!".
- Catelyn Stark's corpse was also desecrated in the aftermath of the Red Wedding. In direct mockery of House Tully's funeral customs, the Freys threw her corpse directly into the Green Fork of the Trident outside of the castle, to rot and be eaten by the fishes.
- Khal Jhaqo mutilated Rakharo's corpse after he killed him, then sent his severed head back to Daenerys Targaryen on his horse. This caused Irri to break down crying, explaining that to the Dothraki, leaving a warrior's body unburned is considered sacrilege, but dismembering after death and then leaving the individual pieces to rot is tantamount to killing his very soul.
- Tywin Lannister, as recounted by his daughter Cersei, killed every man, woman, and child of House Reyne at the end of Reyne Rebellion in his youth. He then had their corpses hung on public display above the gates of Casterly Rock, where they were left all summer until they rotted to pieces (consider that a "summer" in Westeros can last for years).
- Joffrey Baratheon pushed the already thin line of how long it is tolerable to keep an executed prisoner's head on a spike when he left the severed head of Eddard Stark on the traitor's walk in the Red Keep, along with the rest of his household servants. It stayed there rotting for weeks, and one of his son Robb's specific demands sent to the capita (along with recognition of the North's independence) was for his father's bones to be returned. Joffrey was uninvolved and Cersei didn't particularly care, but Tyrion urged his sister to at least send Eddard's bones back as a gesture of good faith. A group of Silent Sisters later accompanied Littlefinger to deliver Eddard's remains to his widow Catelyn while she was meeting with Renly Baratheon in the Stormlands.
- Daenerys Targaryen, after conquering Meereen, had exactly 163 of the defeated Great Masters crucified, to pay them back for the 163 slave-children they left crucified on the road leading to the city in an attempt to intimidate her. Some time later, the nobleman Hizdahr zo Loraq sought audience with Daenerys and begged her to allow him to recover his father's body and give it a proper burial. Daenerys stated that her intention was to leave all of the corpses crucified until they rotted away, as a warning to the surviving former slave-masters. Hizdahr, however, eventually managed to convince her that her point had been made and this desecration was beginning to look needlessly cruel, so she ordered them taken down.
- Lord Ludd Whitehill ordered the desecration of Asher Forrester's corpse after his death at the Ambush at the Harbor. Asher's body was fed to the dogs and his head was decapitated and placed on a pike held by his younger brother, Ryon Forrester. Ludd made Ryon hold up Asher's head at the gates of Ironrath prior to the Battle of Ironrath to disturb Asher's older brother, Lord Rodrik Forrester, his mother, Lady Elissa Forrester and surragate sister Beskha (player-determined).
In the books
In the A Song of Ice and Fire novels, a few more details are given about funeral practices in different parts of the world.
The novels did not specifically mention that members of the nobility in Westeros have their bodies embalmed by removing several vital organs and placing then in seven vases with the corpse (somewhat like mummification). This was introduced in the very first episode of the TV series at Jon Arryn's funeral. At Tywin's funeral in the books, however, it is mentioned that his corpse was "embalmed" in some traditional fashion to slow its decay, so it seems to have been implied that something like this occurs in the novels. Showrunners Benioff and Weiss might not have been the ones who came up with this idea: in the Blu-ray commentary for the first episode, they openly express their confusion at what the vases near Jon Arryn's corpse are there for.
The Faith of the Seven apparently doesn't have any rules against cremation, as it was practiced not only by the Targaryens but also the Tullys and several other groups in Westeros. This is in contrast with Christianity in the real-life Middle Ages, which at times strongly discouraged or even forbid cremation of corpses. This prohibition was due to the strict doctrinal belief at the time that at the Last Judgement, the dead would not simply be resurrected by being "given" new bodies for their spirits, but quite specifically that their original bodies/skeletons would be restored to life/regenerated from their graves (in times of persecution, the Romans - who practiced cremation - would sometimes cremate dead Christians to taunt this belief). Similarly, in Judaism cremation has historically been frowned upon and in some denominations forbidden, and in Islam it is strictly forbidden. No culture has been mentioned in the A Song of Ice and Fire novels that outright opposes cremation.
The Targaryens practice cremation in the tradition of their Valyrian ancestors, though they converted to the Faith of the Seven. When the dragons were still alive, their funeral pyres were lit with dragonflame - Aegon the Conqueror's funeral pyre was lit by the flames of his own dragon, Balerion. A discrepancy was thought to have arisen in Season 3's "And Now His Watch is Ended", when Joffrey Baratheon is giving Margaery Tyrell a tour of the Great Sept of Baelor, and he describes giving her a tour of the crypts below where the "remains" of the Targaryens from past centuries are kept. On the one hand, this somewhat implied that their corpses were buried and not cremated, but on the other hand, the novels never actually said what they did with the ashes of the deceased: in real life some people scatter ashes in bodies of water or to the wind, but others permanently store ashes in ceremonial vases kept in mausoleums. The matter was subsequently explained in the World of Ice and Fire sourcebook (2014) which specified that the Targaryens indeed kept the interred ashes of their dead, in vases stored in the Great Sept's crypts - thus the TV version did not introduce any discrepancy.
It hasn't been mentioned exactly what funerals are like for the ironborn, who follow the Drowned God - though it seems probable that they conduct burials at sea. Apart from the fact that they don't fear drowning and believe that they go to the Drowned God's watery halls when they die, the Iron Islands themselves have tough rocky soil which probably isn't conducive to burial, and they probably don't cremate their dead either, as it is stated that the isles don't have major forests so wood is relatively hard to come by as well.
The Dothraki are described as burning their dead in the main novels. The World of Ice and Fire sourcebook went on to explain that the Dothraki are opposed to working their own agriculture because they believe that the Earth is their mother, and therefore it is defacing her to plow fields in the ground. It is possible that they choose cremation over burial for similar reasons.
In the Summer Islands religion, funerals are not somber occasions mourning the dead but celebrations of the lives they led, with wine and lovemaking.
In the books, desecration of a fallen enemy's corpse is thought to be a highly dishonorable and reprehensible action - not quite as bad as Regicide or Kinslaying, but nearly as bad as Treason, in some cases worse. Desecrating a corpse by simply leaving it on the battlefield for the wolves and crows to eat is considered dishonorable to begin with - actively mutilating a foe's corpse is drastically worse, the more severe the mutilation the worse the offense.
After Robert Baratheon killed Rhaegar Targaryen in single combat at the Battle of the Trident, Rhaegar's surviving followers who had been captured (i.e. Barristan Selmy) begged Robert to let them give Rhaegar's corpse a proper funeral - which, after the Valyrian custom of the Targaryens, was to burn his corpse on a pyre. Robert absolutely hated Rhaegar, his mortal enemy, and for years afterwards Robert openly admitted that he fantasized about killing Rhaegar over and over again in his dreams at night - yet even Robert of all people would not deny Rhaegar a proper funeral, as this would have been a highly dishonorable action.
In Season 3 of the TV series, it is said that Robert privately wished to have the Targaryens' remains thrown into the ocean, but the High Septon at the time objected and Robert didn't push the issue. The novels never gave any indication that Robert wanted to do this - yet even if Robert didn't feel personally obliged to give Rhaegar a proper funeral, he certainly realized that to actually go through with desecrating Rhaegar's corpse would be seen as publicly disgraceful, and much of the realm would lose respect for him. Thus in both versions, Robert ultimately wouldn't risk dishonoring himself by desecrating Rhaegar's corpse, even if he was his hated enemy - compared with how in the novels, the Freys seem outright surprised at how insulted and disgusted the rest of Westeros becomes when word gets out of how they horrifically desecrated Robb Stark's corpse.