The "somehow" is that he tricorder-scanned the Guardian's playbacks of Earth history both before and after the change, so he had recordings of both versions.
Yeah, but as I recall the Guardian's playbacks were being somewhat randomly generated, (i.e. though cycling, not going in any real logical order) and as amazing as that episode is (I'd put it in my top handful of Trek episodes through the whole franchise) it sort of asks us to accept that the tricorder was able to record, and store, two entire timelines in it for comparison. This is quite the feat! Yeah, TOS played fast and loose with the fictional technology but it seems a rather large stretch the tricorder kept two entire timelines on it enough for Spock to make comparisons and find a divergent point that hinges on a meaningless woman getting hit by a car.
Yes, she wasn't strictly "meaningless" in the altered timeline, but it still seems like that's pretty detailed information for a tricorder to pick-up over a scan of random points in Earth's history and various locations as they appear over the course of a few minutes. I mean, that tricorder would have had to have information on *everything* in order to do this. That's pretty damn incredible given that in later Trek series it's implied that computer cores are massive areas on ships, the Enterprise-D has three, and that the information storage seems to be something akin to cloud storage and not all available data is stored locally as there's plenty of times characters say they have to access a grander database to get information.
But, nope,
everything about Earth's history fits on the tricorder's internal storage.
Were any of our heroes vaccinated for eradicated diseases not so eradicated in the past
This is sort of a conceit we have to accept when it comes to time-travel stories. Technically our heroes should be vulnerable to all kinds of things walking around so far in the past, things their bodies aren't going to be immune to because they're things they don't encounter in present-day. Vice-versa is true as well, they're going to
expose contemporary inhabitants to the evolved/adapted diseases and viruses from the future. Things we're immune to due to the changes in technology, forcing the micro-organisms to change, further pushing our immune system to change they're going to bring that back to a time period that is hundreds or thousands of bacterial "generations" behind.
Further, our characters shouldn't really be able to drink or eat anything so far in the past, people in the 19th century didn't exactly drink water that'd been through a purification process and treated with fluoride and the food wasn't raised (both flora and fauna) with a controlled process to prevent contamination or impure food.
Think of pork, for example. Today modern pork is, relatively, safe to eat at medium doneness because big operators of pig farms feed their pigs a controlled diet, usually corn, that minimizes or eliminates pathogens in the meat. Go back even a few decades and you run into the time of "cook pork thoroughly"/"to well done" period because pigs were fed slop. Slop basically being garbage filled with all sorts of nastiness that gets into the meat and, potentially, into the consumer of the pork.
This sort of thing can pretty much be applied to all areas of food types and processing, very, very different treatment and production methods. People back the didn't get food-born illnesses from it, or as severely, because they had immunities to them developed from this being the only kind of food they're exposed to. You or me? A single meal in the 19th century would likely mean us spending the night in an outhouse.
So, a conceit we have to accept in time-travel stories is just that "somehow" these complications from food and disease aren't a problem.