Harry frequently threatens people with "contempt of court" outside the courtroom environment, so therefore would be illegal. Contempt citations are only issued when a lawful order is ignored, someone shows disrespect to the judge during a session, or they disrupt the proceedings.
Dan Fielding's sexual innuendo and unwanted advances, while amusing, would be regarded as being sexual harassment. It would have cost him his job or at the very least forced his removal from the "Night Court" work lineup.
Harry Anderson's romantic affairs with subordinates, while central to the show, were inappropriate even for the 1980s setting of the series. They would have had to end or Harry would have been removed from his role as a judge.