The best way to make a sequel work is to make the stories between the two somewhat episodic OR plan from the get go what the story is going to be. But most of the best Sequels work because they are different stories from the films that proceeded it or upset the dynamic in some way.
Consider some sequels that are considered better than the original. Terminator 2 (T2) is considered the superior film to the original film (Terminator is not a terrible film by any means. T2 is just better.). In this case, everything Terminator did that was loved, T2 did and expanded or improved. But the key here was T2 was never trying to be what Terminator was. The original Terminator was a scifi horror (Sarah Connors was being hunted by a man who would stop at nothing to kill her in Terminator. In T2, Sarah Connors goes on the offensive against the threats). Ironically, every sequel following T2, the sequal tries to one up T2, which to this day, has always been the franchise's toughest act to follow.
You can even see how different the two films end and their view on Time Travel. In the first Terminator, time travel creates a Grandfather paradox. Kyle Reese becomes the father to John Connor after sleeping with his mother while sent to protect her in the past. Sarah Connor in turn raises John to be a great military leader, which in the future John fights the machines with such success that the only way to win is to send a Terminator back in time to kill Sarah, prompting John to send Kyle (who it's implied John knew was fated for this role, hence his selection and the gift of the picture of Sarah).
However, Terminator 2 flips that. While Saving Sarah was important there were several other opportunities in the past for Skynet to kill John. Sarah was a contingency, but the remains of that Terminator were reversed engineered into what became Skynet, thus the heroes are now doing the mission of the villains in the original: Killing Skynet before Skynet is conceived of and born. When they are successful, it leaves viewers with a different issue and Sarah in a better place. Knowing that Judgement Day was inevitable, Sarah was tough on John, to the point that their relationship is strained... but by the end the pair are reunited and Sarah concludes that the future is unknown, giving a far more positive conclusion to the story than the first film.
Toy Story 2 and Toy Story 3 also worked because they didn't retread on Toy Story. The first film was about Woody's fear that Andy no longer loved him with the addition of Buzz Lightyear into the play room's dynamic and is a simple matter of jealousy over the new guy, who isn't trying to replace Woody, but mearly fails to comprehend the situation. When Buzz finally learns that he's a toy and not a real space ranger, Woody has to explain to him why being Andy's Toy is a big deal and an important job.
In Toy Story 2, the script is almost flipped. Woody, who has no idea of the nature of his own franchise's lore, discovers his roots at the same time he comes face to face with the fact that Andy is growing up and won't need his toys forever. This time, he believes his own hype, but in a way that is different than Buzz's delusions in the first film, and it's Buzz that has to remind him of what it means to be Andy's Toy.
In the 3, the entire cast comes face to face with the reality that Andy's outgrown them and have to decide how best they should move on. Here, the concern is miscommunication and a lack of understanding of what they truly want (They think they want to be played with, but what they want is the love of a child who cares for them. The Daycare provides the later but not the former and they realize they shouldn't be bitter over Andy's mistake.).
Other good sequels explore themes that were only touched upon in the original, or not even considered. The Dark Knight forces Batman to realize that while he trained to deal with corruption that follows a rational pattern of thinking, he was totally unprepared for a wildcard situation that is the Joker. When the film begins, he firmly believes he can save Gotham and retire as Batman, unaware that he inadvertently invited something worse into Gotham and a form of corruption that he never considered.
Most sequels that don't work are because it does the same thing as the works that are before it, without giving rise to new ideas. Most of the good ones build on and expand the lore that is loved, not rehash the lore.