In Terry Pratchett's Johnny and the Bomb, chapter 9, Kirsty tries to explain that Wobbler couldn't come back to the future with his friends because he changed history and accidentally killed his own grandfather.
Wobbler gave them a suspicious look.
‘What's going on here?’ he said.
‘Look, I can't explain now,’ said Johnny. ‘You're … stuck here. Er. Apparently, er, something's gone wrong. Er. There's been a snag.’
‘What kind of snag?’
‘Er. Quite a big one.’
Wobbler stopped eating. It was that serious.
‘How big?’ he said.
‘Er. You're not going to be born … er.’ Wobbler stared at him. Then he stared at the half-eaten burger.
‘Am I eating this burger? Are these my teeth marks?’ he demanded.
‘Look, it's perfectly simple,’ said Kirsty. ‘You're alive here, yes, but when we first came back, something must have happened which changed history. Everything anyone does changes history. So there's two histories. You were born in one, but things have been changed and when we got back it was into a different history where you weren't. All we have to do is put things back the way they should be, and then everything will be all right.’
‘Hah! You haven't got a shelf of Star Trek videos as well, have you?’ said Wobbler.
Was Wobbler thinking of a particular episode (or film or other story) of Star Trek here, one that has similar trouble with time travel and the dangers of changing the past?
Please consider only episodes of which both Wobbler (a kid in the UK) could have known of in 1996 (when he lived at the time of this story), and Pratchett could have known of in 1996 (when Johnny and the Bombs was first published).
The dialog about time travel in chapter 1, which foreshadows much of the plot, may also be relevant:
‘But you can't travel in time without messing things up,’ said Yo-less.
‘That's the whole point,’ said Bigmac. ‘That's what you want to do. I wouldn't mind joining the police if they were time police. You'd go back and say, “Hey, are you Adolf Hitler?” and when he said, “Achtung, that's me, ja” … Kablooeee! With the pumb-action shotgun. End of problem.’
‘Yes, but supposing you accidentally shot your own grandfather,’ said Yo-less patiently.
‘I wouldn't. He doesn't look a bit like Adolf Hitler.’
‘Anyway, you're not that good a shot,’ said Wobbler. [skipping the anecdote about Bigmac]
‘I didn't mean actually shooting your actual grandfather,’ said Yo-less, loudly. ‘I mean messing things up so maybe you're not actually born or your time machine never gets invented. Like in that film where the robot is sent back to kill the mother of the boy who's going to beat the robots when he grows up.’¹
‘Good one, that,’ said Bigmac, strafing the silent shops with an invisible machine gun.
‘But if he never got born how did they know he'd existed?’ said Yo-less. ‘Didn't make any sense to me.’
‘How come you're such an expert?’ said Wobbler.
‘Well, I've got three shelves of Star Trek videos,’ said Yo-less.
‘Anyway,’ said Yo-less, ‘if you changed things, maybe you'd end up not going back in time, and there you would be, back in time, I mean, except you never went in the first place, so you wouldn't be able to come back on account of not having gone. Or, even if you could get back, you'd get back to another time, like a sort of parallel dimension, because if the thing you changed hadn't happened then you wouldn't've gone, so you could only come back to somewhere you never went. And there you'd be – stuck.’
They tried to work this out.
‘Huh, you'd have to be mad to even understand time travel,’ said Wobbler eventually.
¹ The Annotated Pratchett File tells which film Yo-less mentions in this line.