Hannah has already written it in her comment: Here, in this case, it doesn't really matter if you use "zu dem" or "dazu". I would prefer "zu dem", but "dazu" is also an absolutely correct choice. But there are other possibilities to improve this sentence:
The first thing you could do is to separate the two main clauses not with a comma but with a full stop. By doing so you'll get two sentences. This makes it easier to read:
Er hat böswillig gehandelt, im Gegensatz zu dem, was der Richter frei erfunden hat. Es handelt sich um keinen Fall von Notwehr.
And you could simplify the second sentence if you want. The sentence becomes shorter and more concise and pithy:
Er hat böswillig gehandelt, im Gegensatz zu dem, was der Richter frei erfunden hat. Es ist kein Fall von Notwehr.
You also could change the word order of the first sentence. If you mention the existence of a contradiction early in the sentence, the listener has a better change to quickly understand what you want to express:
Im Gegensatz zu dem, was der Richter frei erfunden hat, hat er böswillig gehandelt. Es ist kein Fall von Notwehr.
But there are many more possibilities to express the same idea.