The ending shows Hot Rod using the Matrix of Leadership to become Rodimus Prime and destroy Unicron, which hands the Autobots a new leader in place of the fallen Optimus Prime. After the war the Autobots face a changed future as they rebuild.
In my opinion, the ending works because the story and the commercial brief point the same way. Hasbro commissioned the film to help sell its toy line and wanted older characters retired so that new toys such as Kup, Blurr and Rodimus Prime could take their place, according to Slate. A film about succession fits that order neatly. Writer Ron Friedman advised Hasbro to keep Optimus Prime alive, and Hasbro rejected the advice, so the handoff at the end was a requirement before it was a story choice. It could be argued that Hot Rod is the obvious pick because he is the young Autobot who spends the film proving himself, from the Quintessons' capture to the Planet of Junk.
The Matrix is the thread that ties it together. Optimus Prime carried it when he died about 20 minutes in, Megatron was rebuilt as Galvatron to fetch it, and Hot Rod finally activates it. Unicron swallowing Galvatron is the film's tidiest payoff, because the Decepticon sent to collect the Matrix is consumed before he can deliver it. Casting sharpens the point: Orson Welles, who recorded Unicron's lines five days before he died, voices the villain who wants the Matrix, while Leonard Nimoy gives Galvatron his voice.
How does it compare with the later films? In Transformers (2007), directed by Michael Bay, the Autobot leader survives the first fight and the story turns on the AllSpark cube. This 1986 film does the reverse and removes the leader early. Transformers: Rise of the Beasts also puts Unicron on the horizon, sending his herald Scourge after the Transwarp Key. Transformers One goes the other direction and follows Orion Pax becoming Optimus Prime opposite D-16, who becomes Megatron. This film is the one that ends on a leader being replaced rather than created, so watch it with those later stories in mind.