The module path doesn't need to match the repo URL, but if other modules depend on your module, then the go command needs to be able to find your repository given your module path.
The lexical constraints for module paths are documented at
https://golang.org/ref/mod#go-mod-file-ident. In short, the go command needs to be able to form a valid URL from the module path, so only certain characters may be used, there must be a dot in the first path element and so on.
The go command looks up the repository location by sending a GET request to https://<module-path>?go-get=1. It looks for an HTML response with a meta tag that says where the module is located. For example, for the module
golang.org/x/mod, the go command will request
https://golang.org/x/mod?go-get=1 and will get a response with:
That says the module is in a Git repository at
https://go.googlesource.com/mod.
That process is explained at
https://golang.org/ref/mod#vcs-find. There's a special case for GitHub module paths, so if your module is hosted there, you don't need to stand up a server for that URL. Also, if a path component ends with ".git", ".hg", etc, the go command will use everything up to there as the repository URL without performing the lookup.