Because of the new. It treats the function afterwards as a class constructor and calls it to construct a new instance. It might be a but easier to understand if you take:
 function Something() {
   alert("works");
 }
 const sth = new Something;
Now just move the function and you got:
 const sth = new function() {
  alert("works");
 };
which is exactly what happens in your case.
solved javascript function executed without calling the function [closed]