The organizers of the funeral arrange for hiring the band as part of the services. When a respected fellow musician or prominent member of the community dies, some additional musicians may also play in the procession as a sign of their esteem for the deceased.
A typical jazz funeral begins with a march by the family, friends, and a brass band from the home, funeral home or church to the cemetery. Throughout the march, the band plays somber dirges and hymns. A change in the tenor of the ceremony takes place, after either the deceased is entombed, or the hearse leaves the procession and members of the procession say their final goodbye and they “cut the body loose”. After this the music becomes more upbeat, often starting with a hymn or spiritual number played in a swinging fashion, then going into popular hot tunes. There is raucous music and cathartic dancing where onlookers join in to celebrate the life of the deceased. Those who follow the band just to enjoy the music are called the second line, and their style of dancing, in which they walk and sometimes twirl a parasol or handkerchief in the air, is called second lining.
Source: Jazz funeral – Wikipedia