This is addressed in the film's Incredible Cross-Sections tie-in factbook. In short, it's a combination of unheard-of levels of computer processing power (using hyperspace as a way of compressing processing time) as well as advanced hyperspace sensors and records of millions of previous hyperspace transits.
It's still a guess, but a guess based on trillions of probability calculations.
The First Order tracks targets through hyperspace using a combination
of technological advances and brute-force data crunching. The
shipboard tracking control complex boasts the data-sifting power of a
planetary intel hub, linking huge computer arrays to databanks loaded
with centuries of combat reports and astrogation data.
A static hyperspace field generated around the machines then
accelerates their processing power to unheard-of levels. A targets
last known trajectory yields trillions of potential destinations, but
the system can assess them with terrifying speed.
For a bit of fun, it's worth pointing out that we see the system in its infancy in Rogue One, one of the research projects with data on file at the Scarif base.
