Hi, welcome to Flarum !
Are you trying to do it inside an extension or via an external script ?
The User::register() is only intended to be used from inside Flarum, in the core or an extension.
To register a user from an external script, either use the API or connect directly to the database.
Using the API is the most elegant solution here as you can't really mess up anything and Flarum will take care of dispatching all events and extensions can do their things. There are example on this forum on how to connect to the API with a master token so you're able to create new users.
Let us know if you need any help with one of those solutions !