When barristers are called to the Bar they are, traditionally, given a slim volume covering professional etiquette and advocacy. The only bit of it that I could remember was the stern advice that humour had no place in the courtroom and I was to avoid it at all costs. I only remembered that because I promptly decided that that was one bit of advice that I would never follow, and I never did. Mostly that was humour applied to the circumstances and the evidence as it emerged, but even a joke, in the true sense, may be told if it illustrates a point you are making. The advocate has to be himself. If he is naturally serious he must be serious, if naturally humourous, humourous, and so on. And that applies whether prosecuting or defending. The late George Carman QC would not have had such a successful career had he not injected humour into his cases, for that was his nature.
I have known a few judges who injected humour, even in the summing up to the jury. HHJ Sir Harold Cassel QC, a natural renegade all his career, was very dangerous to whichever side he applied it when doing that, but he never got appealed for it. As I say, if it is natural to the individual, they should behave that way.
Witnesses often give answers which are amusing. I had one foreign defendant, in a case concerning sex with a minor, who said he always took precautions when having sex, using Dulux. It was difficullt for the jury to keep straight faces at this announcement, though they did try.