In fact, judges do this sort of thing all the time. One of the major powers they exert is on what evidence may or may not be heard in court. In a recent 2nd amendment case, the judge ruled that the person being prosecuted could not testify because he would claim the defense that the law was unconstitutional.
Exactly, and that is unconstitutional and tyrannical of the judge.