A county court in central China has sentenced four men to prison for digging up and selling corpses on the black market to enable "ghost marriages", a millennia-old custom of burying deceased bachelors alongside newly deceased wives so that they will not grow lonely in the afterlife.

On Saturday, the Xi'an Evening News reported that the Yanchuan county court in Yan'an City, Shanxi province, sentenced each of the men to more than two years in prison for stealing 10 female corpses, cleaning them up and counterfeiting their medical records to boost their prices, and selling them on the black market for a total of £25,000.

Ritual ghost marriages, which may date back to the 17th century BC, are increasingly rare in contemporary China – Mao Zedong tried to eliminate them when he assumed power in 1949 – but they are still practised in rural parts of Shaanxi, Shanxi, Henan, Hebei and Guangdong provinces. Families often employ a matchmaker to help find a suitable spouse for their deceased loved ones.

The four men, with surnames Pang, Bai, He and Zhang, exhumed the corpses in the winter of 2011 from a smattering of arid, coal-rich counties in Shanxi and Shaanxi provinces.

The state-run Global Times newspaper reported in 2011 that an influx of coal money to parts of northern Shaanxi province bolstered the area's underground corpse trade, with a newly wealthy but superstitious demographic suddenly being able to afford high prices for desirable postmortem mates. Some are known to purchase their corpse brides straight from hospitals, where they cut deals with grieving families.

This is not the first time that ghost marriage intermediaries have fallen on the wrong side of the law. One woman died over the lunar new year in February 2012 and was sold by her family to the family of a recently deceased young man for about £3,700; soon afterwards, police caught a graverobber selling her twice-exhumed body to another family for slightly less.

In 2009, a grieving father in Xianyang City, also in Shaanxi province, paid a team of graverobbers £2,700 to find a suitable bride for his son, who had died in a car crash. They were arrested for exhuming the remains of a teenage girl who had killed herself not long after failing her college entrance exams.

According to the Global Times, less affluent families who desire ghost marriages may use a non-human proxy for the corpse bride, such as a silver statuette or a doughy human-shaped biscuit with black beans for eyes. Some may buy an old, rotten corpse at a discounted price, dress it in clothing and reinforce its skeleton with steel wire.

The tradition has its own set of customs and rituals, including postmortem marriages with sumptuous feasts and dowries, according to the report.