A man with paranoid schizophrenia who killed three elderly men wrongly thinking they were sex offenders or serial murderers has been found not guilty of their murders by reason of insanity and will be detained in a secure hospital.

Alexander Lewis-Ranwell was having acute psychotic delusions when he used a hammer and spade to kill Anthony Payne, 80, and twins Dick and Roger Carter, 84, at their homes in Exeter, believing that he was acting with the police’s blessing because he had just been freed on bail following an earlier violent attack.

During the trial there was no dispute that he killed the three men. The case centred on whether he knew that what he was doing was legally and morally wrong. The jury ruled that he did not and cleared him of three murders.

Lewis-Ranwell was given a hospital restriction order and Mrs Justice May told the jury he would be cared for in a secure setting until agencies could be absolutely confident that he could be released back into the community.

During the 38-year-old’s trial at Exeter crown court, it emerged that he began the series of killings just hours after being bailed by police following an earlier vicious assault on another man in his 80s.

Five health professionals saw him in the days before the fatal attacks but no full mental health assessment was carried out, even though a police inspector concluded he could pose a serious risk to the public.

Alexander Lewis-Ranwell was released from Barnstaple police station, hours before he killed three men. Photograph: CPS/PA

After he was finally detained, Lewis-Ranwell told a psychiatrist: “I cannot believe no one helped me – they let me out when I was unwell” and another psychiatrist who has studied the case said he believed Lewis-Ranwell was “one of the illest people” he had come across.

Before returning their verdicts, the jury gave a note to the judge in which they raised their concerns about the “state of psychiatric services” in Devon and said they hoped that “failings in care in Alexander Lewis-Ranwell’s case” would be addressed.

Speaking at the end of the trial, the Carter twins’ family said they were quiet and kind gentlemen and added: “This case will, we are sure, raise questions regarding the care, monitoring and custodial treatment of the mentally ill. We can only hope that in the course of time, lessons learned are put into practice to ensure that there is no repetition of these awful events.”

The jury was told that Lewis-Ranwell, a former public schoolboy from Croyde, north Devon, was arrested on the morning of 8 February after being caught letting animals out of a farm.

While in custody in north Devon he declined a mental health assessment and denied he was a risk to himself or others. His mother, Jill Lewis-Ranwell, phoned police and asked for his detention to continue because he had nowhere to go. He was charged with burglary and damaging his police cell but was freed in the early hours of 9 February.

Seven hours later he attacked 83-year-old farmer John Ellis with a saw and was arrested again. An inspector reviewing his detention wrote that Lewis-Ranwell “potentially presents as a serious risk to the public if released”. The victim also called for him to be kept locked up, expressing concern that he was a danger.

During the two periods of custody, five medical professionals saw him but they did not deem him acutely unwell and a full mental health assessment did not take place.

The police consulted the Crown Prosecution Service over the attack on the farmer but the decision was made that there was not yet enough evidence for him to be charged. Lewis-Ranwell was released on bail at 9.32am on 10 February.

By 12.30pm Lewis-Ranwell had travelled from north Devon to Exeter and was in the St David’s area of the city. He stopped at the terraced house where Payne lived and read a note on the door saying the occupant was an 80-year-old man.

Lewis-Ranwell deludedly believed the pensioner had kidnapped a girl 25 years before and was keeping her in his cellar. He went in and bludgeoned Payne to death with a hammer.

Less than three hours later, Lewis-Ranwell was in the St Thomas area of the city outside the home of the Carter brothers. He took up a spade from the garden, went into the house and beat both brothers to death with the tool, wrongly believing they had been involved in child abuse and torture.

After the attacks, Lewis-Ranwell slept rough and at 5am on Monday 11 February he carried out a violent but non-fatal attack on a hotel night porter. Police were called and he was Tasered and arrested.

At Broadmoor secure hospital, consultant forensic psychiatrist Paul MacAllister found Lewis-Ranwell to be sensitive, intelligent and articulate when he was well. But when he was ill he was living in a very frightening, dream-like world.

“He had the clear belief that the police were aware of and sanctioned his actions,” MacAllister told the court. “He believed that the police were shortly to arrive to support him.”

Both Devon partnership trust and Devon county council, whose staff were involved in the case, said they would welcome a chance to learn lessons from it. G4S Health Services, whose forensic medical practitioner assessed Lewis-Ranwell while he was in custody, said it stood by his decision that the detainee did not need a full assessment but pointed out he had recommended that the local mental health team saw him next morning, which did not happen.