Originally it was used as an anchor to jump to an element with the same name/id.
However, nowadays it’s usually used with AJAX-based pages since changing the hash can be detected using JavaScript and allows you to use the back/forward button without actually triggering a full page reload.