You're right that the rod would keep swinging under ideal physical circumstances, but this wouldn't be due to gravity. If you imagine the rod at the horizontal point of its rotation, there is a gravitational force on one side pulling on one weight, trying to speed up its rotation, and a gravitational force on the other side pulling on the other weight, trying to slow down its rotation. In the language of physics, we say that the net torque is zero (or that the net moment is zero). What this means is that gravity does not have any effect on the rod, and the rod would spin just as if gravity weren't there.
The fact that the rod keeps spinning indefinitely is a statement of the conservation of angular momentum, which states that when there is no torque acting on a rigid object, its speed of rotation is constant. Its the rotational analogue of the conservation of linear momentum, which states that when there is no net force acting on an object, its velocity is constant.
Now why can't we extract power from this rotating rod? To answer this, imagine that the physical circumstances were not ideal. For instance, imagine that there was some friction at the pivot. This friction acts as a torque on the spinning rod, such that its speed of rotation decreases, rather than stays constant. The effect is to transfer energy out of the rod, which slows down, and into the bearings and the pivot, which warm up (that is, gain thermal energy). The total energy is conserved.
Attaching a dynamo to the pivot, in circumstances without friction, has the same effect. Ultimately you want your dynamo to generate electrical energy in the wires connected to it. To do that, you need to draw energy from some other source - in this case, the spinning wheel. This is the law of conservation of energy, and it implies that our rod will slow down until it eventually stops.