A man on trial accused of murdering a student with a cricket bat told doctors two ghosts were communicating with him, a jury heard.
Dawood Khan's behaviour was "bizarre and out of touch with reality" after the violent death of Nazeer Ahmed, Bradford Crown Court was told.
Khan was declared unfit for police interview and detained under the Mental Health Act.
Doctors at Stockton Hall Hospital, near York, where he has been since, reported he believed he was controlled by black magic and two ghosts.
He refused to eat for ten days, telling staff he believed the black magic curse had poisoned his food.
Khan, an illegal immigrant from Afghanistan, denies murdering Mr Ahmed, 22, a student at the Yorkshire College in Manningham Lane, Bradford, on May 31 last year.
Khan lived in Rupert Street, Keighley, with four other men, including Mr Ahmed, who was found battered to death on the sofa in the living room at the house.
He was attacked while sitting down to an afternoon meal. Up to eight blows had been rained on his head, chest and hands.
Ambulance staff told the court Mr Ahmed had no pulse or heartbeat when they arrived shortly after 4pm.
The court heard Khan was interviewed by detectives at the hospital in November.
He told them: "I was out of the house. I have no knowledge of the murder."
He said he went looking for work in Keighley and ran off when he saw police at the house because he feared he would be deported.
He said Mr Ahmed was working on a computer in his bedroom. The men were good friends and were laughing and joking. Mr Ahmed was trying to teach him Urdu.
When Khan was charged with murder, he told detectives: "I haven't done this," the jury heard.
The trial continues.
Comments: Our rules
We want our comments to be a lively and valuable part of our community - a place where readers can debate and engage with the most important local issues. The ability to comment on our stories is a privilege, not a right, however, and that privilege may be withdrawn if it is abused or misused.
Please report any comments that break our rules.
Read the rules hereComments are closed on this article