How do I use Url::setUnrouted() in a custom module?
Url::setUnrouted() is really an internal method used by the URL class.  It is used by the static constructor Url::fromUri() when the URI passed as argument isn't a route.

In general, you should create URL from one of the static constructor functions, and then use the public methods to change anything that you need.  And, paths in your own code should be set up as routes, whenever possible.

If you really need to create an unrouted URL to a static resource that can't be handled through other method (eg, JS and CSS should be handled using #attached), then you would do something like the following:

$url = Url::fromUri('base:some/path/foo.txt');