Consider a system where a block is to be raised from the ground to a height of 1 meter above the ground. It is given that when the force acting on the block and its displacement act in the same sense, the block gains energy. On the other hand, when both quantities act in opposite senses, the block loses energy.
Back to our example. At the ground reference level, let's assume the energy of the block is zero (no potential energy and no kinetic energy). As the block rises towards the 1-m height, it is acted upon by two equal and opposite forces: the lifting force and weight. The lifting force and the displacement are in the same sense so energy is gained by the block. However, weight and displacement act in opposite senses so the block loses an amount of energy equal to that supplied by the lifting force. Now, the block is at 1-m height with zero net gain in energy.
The question is: The gravitational potential energy of the block clearly increased since there was a change in elevation. However, we assumed in the previous paragraph that the block did not gain or lose any energy. So where is this energy coming from?