I had a similar idea when I was young and learned about electromagnetic induction: install a powerful magnet to the moon and a coil on the earth. The changing magnetic field will give you free energy!
Of course, there's such a thing as the law of conservation of energy. It is probably the most well-tested law of physics. Numerous attempts have been made to obtain free energy, with all of them failed.
How would my scheme fail, then? Obviously, powerful enough magnets and big enough coils are not feasible, but even if they were, it would simply extract energy stored in the earth-moon system. Quite similar to what is done using tidal power, with the exception that my scheme is not feasible but tidal power is. Both of them extract energy from the earth-moon system which actually has plenty of energy.
In your case, conversion efficiencies of the various mechanical->electrical and electrical->mechanical conversions are not 100%. Because they are less than 100%, a given amount of mechanical energy turns into less electrical energy and even less mechanical energy, so the engine in this system will not rotate forever, and definitely will not allow you to divert free energy from this system to other purposes. If you could get 100% conversion efficiency with no friction, then in that case it would rotate forever, but attempts to extract energy would slow down the rotation which would gradually stop then.