"He suffered delusions – a genuine belief something is the case when it was not so at all," Prosecutor Richard Smith QC told the court.
The victims were not involved in any paedophile ring.
According to Smith, Lewis-Ranwell killed Anthony Payne first, with a hammer.
"The defendant stopped at Mr Payne's house and read a note on the door which spoke about the occupant being an elderly man of 80 years of age," he told the court.
"The defendant went in through the front door and found or followed Mr Payne upstairs to the bedroom.
"The defendant took up a hammer and bludgeoned Mr Payne to death with blows to the head."
A couple of hours later, he reportedly walked down Cowick Lane.
One of the elderly brothers tried to usher Lewis-Ranwell away but he went around the back of the house, found a spade, and killed the two brothers.
He climbed over a wall and "once inside beat both brothers to death with blows to the head with the spade", Smith said.
The court heard that the defendant was released from police custody on the morning of the killings, after being arrested the day before over a violent attack on a farmer.
As he was being booked into custody, he grabbed an officer's Taser. He was taken to the floor and put in a cell, where he urinated and spat.
The case has been adjourned.