In the hobbit films, Sauron captures Gandalf. Later, in the Lord of the Rings, Gandalf appears and tells Frodo that the One Ring needs to be destroyed.
What happened was, Sauron and Gandalf hatched a plot to get rich. Sauron insured the One Ring for a ton of money, and his “enemy,” Gandalf, made sure it got destroyed. Then Sauron faked his death and they split the money. It’s so obvious.