The man was being held for allegedly burning a copy of the Koran in public. The incident took place on the outskirts of Bahawalpur, in Punjab province.
Witnesses said hundreds of people looked on as he screamed for help.
Pakistan's controversial blasphemy law imposes the death penalty for insulting Islam, but it is rarely carried out.
The area where the lynching took place is home to hundreds of madrassas - religious schools - run by radical Islamist or sectarian groups.
Police said they detained the man after locals complained that he had desecrated the Koran.
But before the allegation could be investigated, thousands of angry people surrounded the police station, police said.
"They were demanding that we kill him in front of them, or they'll take him away and kill him themselves," police inspector Ghulam Mohiuddin told the BBC.
After officers unsuccessfully tried to calm the crowd, it attacked the station, as police tried to disperse it with tear gas. Several policemen were wounded in the violence.
The mob put up roadblocks to prevent police reinforcements from reaching the area, officers said.
"We were totally outnumbered. There were too many of them and they were hysterical. Eventually, they succeeded in taking him away," said one.
The man was reportedly beaten and dragged to the spot where he is said to have desecrated the Koran.
The mob then poured petrol on him and set him on fire, according to witnesses.
Police say they are trying to identify the victim, who was said to be mentally unstable.
"The man had no idea what was going on," said an official.
"While he was in our custody, he kept laughing and chanting."
A case has been registered against unknown attackers. No arrests have been made yet.
A Pakistani mob has taken a man accused of blasphemy from a police station and burnt him to death, police say.