I don't think there's any general injunction about getting the science right, but sometimes getting it wrong can be a distraction. One example that's been discussed by various critics comes from Lord of the Flies. Piggy's glasses are used to focus sunlight and start a fire. But Piggy is nearsighted; his lenses would be concave rather than convex and couldn't be used to start a fire. (Thanks to John Holliday for this example, which he discusses in his dissertation.) Many readers won't realize the problem, but the glasses and Piggy's nearsightedness aren't just an incidental plot element. This is the sort of detail that Golding could have gotten right and once you know that it's wrong, you may never be able to read those scenes in the same way.
Needless to say, this doesn't show that getting the science right always matters. It surely doesn't. It's also plausible that these things will be matters of degree. The more esoteric the bit of science, and the less central to the story, the less it's likely to matter whether the author gets it right. Also, if we couldn't reasonably expect the author to get it right (say, because the relevant bits of science weren't known when the story was written), we will be more forgiving, though even we may need to make an effort not to let ourselves be jarred by the inaccuracy.
We could add that it's not just science that matters. I remember as a boy reading a Hardy Boys story in which part of the action took place in eastern Canada, in "St. John's, New Brunswick." This annoyed me and distracted me; there is no St. John's, New Brunswick. There is a St. John's, Newfoundland. There is a Saint John New Brunswick (and yes, the spelling matters.) The author could easily have gotten this detail right with a minimum of research. The story, of course, is a fiction. But like most stories, it's a fiction intended to bear a certain relationship to the real world. Imagine, for instance, an author who set a scene in Faneuil Hall in Boston, Connecticut. I'd need a pretty good reason to forgive the author for that oversight. I'd also need a pretty good reason to forgive an author who wrote a story with a physics professor character who said that electrons are bosons.
So even though fictions are, well, fictional, getting the facts right can make an aesthetic difference, and scientific facts can be among the ones that matter.