The 2 essentials according to the principle, to make a person guilty are-
1. He must be aware that the proceedings are pending in the court.
2. There should be a publication in relation to it.
X is guilty of contempt of court as he favored an accused who was being prosecuted for assaulting a police officer. His statement that the accused is going to be punished for being honest by the court shows that he was aware of the pending proceedings against the accused in the court of law.
There was publication since he delivered a lecture about the matter and it interferes with the proceedings pending in the Court.
Therefore, he is guilty of contempt of court.