It is based on the value set for environment variable GIT_DIR. It is set to the root of the repository when the hook starts running. Many hooks, especially those doing a pull from another repo, unset ( and reset) this environment variable as needed.
The current answers appear to be outdated. As of 2.9.0, the docs state the following:
Before Git invokes a hook, it changes its working directory to either
the root of the working tree in a non-bare repository, or to the
$GIT_DIR in a bare repository.