David Cameron has been criticised by a judge for publicly backing Nigella Lawson in the middle of a fraud trial in which she is a main prosecution witness.

Judge Robin Johnson told a jury trying the fraud case of Lawson's former personal assistants Elisabetta and Francesca Grillo that they should ignore the prime minister's comments published this week in the Spectator.

Cameron used an interview with the editor of the magazine, Fraser Nelson, to say that he was for "team Nigella" and he thought she was a "very funny and warm person" and he was "a massive fan".

The judge, sitting at Isleworth crown court, said the comments had been reported widely and it was "of regret when people in public office comment about a person who is involved in a trial that is in progress".

He continued: "It is inconceivable that some of your number have not seen the reports. The defendants feel aggrieved as the comments, although they do not specifically deal with matters in this trial, are favourable to Miss Lawson. The fact they feel aggrieved is not without justification. You will realise that what public figures say or feel about a witness in this case has no bearing on matters that you decide."

He also apologised to the jury for the court time taken up by consideration of the prime minister's comments.

"It has had the effect of wasting almost an entire morning of court time that should have been devoted to the evidence and issues in this trial," he said.

Lawson gave evidence in the ongoing case last week as a prosecution witness and admitted using cocaine and cannabis. Cameron's comments were published this week in an interview in this week's Spectator under the headline: "Why he's on team Nigella."

Cameron was asked: "Are you on team Nigella?"

"I am," he answered. "I'm a massive fan. I've had the great pleasure of meeting her a couple of times and she always strikes me as a very funny and warm person, but I'm also an amateur cook and I like her recipes. Nancy [Cameron's nine-year-old daughter] and I sometimes watch a bit of Nigella on telly. Not in court, I hasten to add."

Nelson wrote: "I ask a question I feel sure he will dodge about the trial of Charles Saatchi's former housemaids and the revelation that his ex-wife Nigella Lawson used cocaine. Her fans have rushed to her defence: 'team Nigella' is used as a hashtag on Twitter and even sprayed on city walls. Is the prime minister on team Nigella?"

Downing Street sources said Cameron had been asked a question about Lawson and his response referred to her cooking, not the court case.

Elisabetta Grillo will give evidence this afternoon. The trial continues.