It means "Going to sleep" or something like that. In 1902, mattresses were often sacks stuffed with straw or hay, which is why people also say 'hit the sack' as well.
speaking of which, Imma hit the hay cuz Its like 10 PM rn and I have a test tomorrow, cheerio mate