The law of conservation of energy states that energy can be neither created nor destroyed. It can only be converted from one form to another.
Consider the case of an oscillating pendulum.
When a pendulum moves from its mean position P to either of its extreme positions A or B, it rises through a height h above the mean level P. At this point, the kinetic energy of the bob changes completely into potential energy. The kinetic energy becomes zero, and the bob possesses only potential energy. As it moves towards point P, its potential energy decreases progressively. Accordingly, the kinetic energy increases. As the bob reaches point P, its potential energy becomes zero and the bob possesses only kinetic energy. This process is repeated as long as the pendulum oscillates.
The bob does not oscillate forever. It comes to rest because air resistance resists its motion. The pendulum loses its kinetic energy to overcome this friction and stops after some time.
The law of conservation of energy is not violated because the energy lost by the pendulum to overcome friction is gained by its surroundings. Hence, the total energy of the pendulum and the surrounding system remain conserved.