This time requirement is pretty lenient as long as you've been through the game before and you have a plan. I followed this awesome guide on Steam
, which is extremely detailed in terms of pathing and objectives.
It's up to you to understand boss encounters, but there is a lot of leeway since an optimal run takes maybe 2h15m. The achievement was originally for completing the game in under three hours on the PC version but changed to five hours in an update.
There's really no major rush to be able get through the game in under 5 hours, so be sure to smash geo rocks and kill enemies when you see them as geo is an extremely important resource. You definitely want to have 1800 geo for the Lumafly Lantern before going through Crystal Peak as a few areas there are difficult without illumination. The guide I linked considers the lantern a convenience for Crystal Peak but I found it to be a necessity.
A few of the battles, especially the Watcher Knights and Hollow Knight, were rough with low damage and health. So feel free to go out of your way for grubs and mask shards in addition to the nail upgrades to make your life easier in the long run. Be sure to hit the bench near the Watcher Knights so you don't have far to travel should you struggle with them like I did.
Time does not accumulate when you have the game paused with
(as mentioned by NINja227), so be sure to pause and not just be in your inventory menu if you need to take time to plan or figure something out.
Additional info can be found on the Hollow Knight wiki