To understand why, let's consider a simple roller coaster with a single hill and a single train. The train is pulled to the top of the hill by a chain, which is driven by an electric motor. Once at the top, the train is released and coasts down the hill. As it does so, it picks up speed and gains potential energy.
At the bottom of the hill, the train has reached its maximum speed and has the maximum amount of potential energy. This energy is then used to pull the train back up the next hill. The train slows down as it climbs the hill, and its potential energy is converted into kinetic energy.
By the time the train reaches the top of the next hill, it has lost all of its potential energy and is moving very slowly. The chain then pulls the train back up to the top of the first hill, and the process repeats.
So, while roller coasters do use electricity to pull the train to the top of the first hill, they generate enough energy during their operation to pull themselves back up to the top of the next hill. This means that they are actually quite energy-efficient rides.