Judge Roger Thorn lambasted Cockerline, 42, after hearing how he was often seen around Hull with the offending badge pinned to his beanie hat.
He was particularly angered by Cockerline’s decision to display it as he entered Hull Crown Court two days before Remembrance Sunday.
Judge Thorn, himself wearing a traditional poppy, told him: “You’re in enough trouble. It's a disgrace you were wearing a swastika badge on your hat at this time of Remembrance.
“Ironically, being a druggie and a weirdo, you would have been the first person that the Germans would have gassed!"
Cockerline, who has convictions for harassment and criminal damage, was appearing before Judge Thorn for a monthly probation review imposed for breaching court orders.
He remembered to take off his hat as he entered the courtroom, but was confronted after the judge learned of his habit of showing off the swastika during meetings with probation staff.
The judge asked him what it was all about. Cockerline, who was standing in the well of the court, took his hat out of his pocket and showed him the swastika.
He said he had been given it in a direct swap for a German beer glass.
'Nazis would have gassed you' judge tells criminal wearing swastika - Telegraph