Yang Qingpei murdered his parents on September 28 last year when they refused to give him money, the Qujing City Intermediate People's Court said on its official microblog account.
Fearing he would be discovered, he then killed 17 of his neighbours, including three children, and fled to Yunnan's provincial capital Kunming.
He pleaded guilty and apologised to the relatives of his victims at the start of his trial on July 19.
The court ruling also condemned Yang's "particularly cruel" modus operandi and "evil plot".