As one of the current answers points out, referencing a ticket number is important for traceability. This can be relevant to:
- Understand the higher-level perspective on why changes were made. You should aim to make commit messages self-contained, i.e., so they can be understood in isolation. But, when you are interested in understanding how multiple commits all work together towards a common goal, ticket numbers which link to external documentation come in handy. Note: pull request descriptions on GitHub fulfill a similar function, but depending on your software development process, ticket descriptions tend to be more end-user oriented, and pull request descriptions more technical. Also, you may not want to depend on a specific version-control system feature.
- Fulfill legal requests such as audits.
However, I personally feel it's better to reference ticket numbers from commit descriptions instead of their title.
The commit title should be concise and acts as a summary. Adding a ticket number to a commit title steals some of the precious space which could be used communicating whether the particular commit is relevant to whoever is reading a commit history (titles are clipped past a certain point in many tools visualizing commit histories).
In contrast, a commit description allows adding additional detail/motivation; exactly what you would expect to see when you open the linked ticket number, i.e., the "higher-level perspective" described earlier.
Furthermore, ticket numbers without an explanation can be ambiguous. Often, work is performed as part of working on a particular ticket which may not be directly related to it. E.g., refactoring work in preparation of implementing an actual feature. Somebody looking for documentation in the referenced ticket number may get more confused than before if what is described there is not clearly related to the observed changes.
Therefore, I would argue ticket numbers belong in commit descriptions instead, in which they can be prefixed with clearer intent, such as "Preparatory refactoring for XXXX."