The Kabul primary court also sentenced eight people to 16 years in prison while 18 others were found not guilty after a three-day trial broadcast live on national television.
A furious mob turned on the woman, 27-year-old Farkhunda, on March 19, beating her in broad daylight and setting her body ablaze on the banks of the Kabul River.
The attack came after an amulet seller, whom she had reportedly castigated, falsely accused her of burning the Holy Quran.
Her killing triggered protests around Afghanistan and several world cities, drawing global attention to the treatment of Afghan women.
Forty-nine people including 19 police officers accused of failing to prevent the attack were arrested.
The three-day trial saw the suspects facing various charges including assault, murder and encouraging others to take part in the attack.
Judge Safiullah Mojaddidi, announcing the verdict, said Zainul Abiddin, Mohammad Yaqub, Mohammad Sharif and Abdul Bashir would be hanged.
“It is not a final decision and their right to appeal is reserved,” the judge said.
Farkhunda’s parents, who were in court on Wednesday, said before the verdict was announced that they “only want justice, nothing else”.
“I want justice to be served and the criminals who killed an educated girl… to be punished,” her father Mohammad Nadir told the court.
The verdicts on the policemen accused of “negligence of duty” will be announced on Sunday and the court also ordered security forces to arrest three other key suspects.
Farkhunda’s murder, caught on cellphone cameras and circulated on social media, sparked demonstrations around the country.
The backlash highlighted the angst of a post-Taliban generation in Afghanistan — where nearly two-thirds of the population is under 25 — that is often torn between conservatism and modernity as the country rebuilds after decades of war.
Farkhunda’s case has also become a symbol of the violence that women face in Afghanistan, despite reforms since the hardline Taliban regime fell in 2001.
Last October five Afghan men were hanged over a gang rape that sparked a national outcry, even though the United Nations and human rights groups called for President Ashraf Ghani to stay the executions.
A recent UN report entitled “Justice through the eyes of Afghan women” urged the government to strengthen access to justice for women victims of violence.
Most cases of violence against women were settled through mediation, highlighting perceived deficiencies in the Afghan criminal justice system including allegations of corruption and abuse of power, the report said. (AFP)