The day before, a heated debate over religion with fellow students broke out at the dorm and led to people accusing Khan of blasphemy. That attracted a crowd that grew to several hundred people, according to witnesses.
The mob kicked in the door, dragged Khan from his room and beat him to death, witnesses and police said.
The death in the northwestern city of Mardan is the latest violence linked to accusations of blasphemy in Pakistan.
Those who knew Khan described him as an intellectually curious student who openly professed devotion to Islam but asked many questions.
"Whatever he had to say, he would say it openly, but he didn't understand the environment he was living in," said one of Khan's teachers at Abdul Wali Khan University, who declined to be named for fear of retribution.
Crimes related to blasphemy are a serious offence in Pakistan, and penalties range from small fines to the death sentence.
At least 65 people have been murdered over blasphemy allegations since 1990, according to figures from a Center for Research and Security Studies report and local media, and dozens more convicted of the crime are currently on death row in Pakistani jails.
The Pakistani government has yet to comment publicly on Khan's killing.
In March, Prime Minister Nawaz Sharif issued an order for the removal of blasphemous content online, and said anyone who posted such content should face "strict punishment under the law".
Police say they have arrested 20 suspects involved in Khan's murder and have found no evidence to substantiate blasphemy allegations.
IMAM REFUSES LAST RITES
"They could have easily saved his life but they stood away from the mob ... I heard one officer say it's good that they sent this non-believer to hell," he said.
Mardan police chief Mohammad Alam Shinwari denied the allegation that officers did not do enough to save Khan.
"When we entered the campus, he had already been killed and the mob was trying to burn his body," he said.
In Khan's home town of Swabi, around 60 km south of Mardan, his father, Iqbal Shaer, said the accusations of blasphemy were unfounded.
"First they killed my son and now they are adding salt to our wounds," he told Reuters.
Shaer, who runs a small business selling biscuits and chocolates to local retailers, said he had always been a lover of poetry and literature and encouraged his children to express themselves and appreciate the arts.
He added: "My wife told me this morning that she spent her life taking care of her son, but those who killed him have wasted that long struggle."
At Khan's funeral, the imam at the local mosque refused to read the last rites, according to Swabi resident Salman Ahmed. A technician who was asked to do so in the cleric's place was confronted by several people afterwards.
Khan has since been buried.