Suppose we would create a river, canal or a tube around the earth and water would flow in it. Where would it flow? And if we put some turbines in this flow, could it produce free energy?
Quite possibly, but why? Main source of its motion would be tides. Works to harness tidal energy are already advanced. And without artificial restraints, you have oceanic currents near the equator to draw from. All you need to do to have it in your world is to make it cheaper. For that, you will rather remove costs than add them. So, no pipe, no channel, just get the energy.
No, a world-circling river would not flow of itself under known physics, simply because it went all the way around a planet. (Conservation of energy, ditto Green's Theorem re closed-path integrals.) So putting turbines in it wouldn't produce free power. Sorry, this won't work unless your world has some premise or other handwavium for inducing the water to flow. BTW, the Riverworld Series by Farmer has something similar, but it's clearly artificially powered (via alien tech far, far above our current level.)
Qualification: There are current loops in our oceans, such as the one circling Antarctica. One could in principle get power out of currents like those with turbines or similar, but the energy is coming either from the sun's fusion reactions or radioactive decay, however indirectly. No perpetual motion involved.
You can only get energy from moving the water from a place with gravitatory potential energy (a high place) to a place with low gravitatory potential energy (a low place), and you can only get as much energy as the difference between the potential energy between those two points (additionally, some is lost as heat).
That is why rivers flow from high places (mountains) to low places (sea, Dead Sea Valley) and not the other way. If there is no energy differential water just does not move.
In your canal, water will stay in lower zones and won't move into higher zones unless you move it (putting additional energy, not getting energy). If all the zones are at the same (gravitational) level, water will almost not move (the exception being tidal energy -which already happens without the need of building a canal around Earth - and a very, very tiny Coriolis force which would not be worth the effort).
Yes (perhaps), and no
It would not flow anywhere by itself because that would need a source of, you guessed it, energy. Since it is a closed loop, that cannot be any source of energy admitting a potential - not gravity, not electrostatic fields.
If it was free enough of viscous effects from the shores and the bottom, it would experience some slight Coriolis force, but nothing worth mentioning.
If you had a large enough satellite and the river lied in the orbit's plane, it would experience tidal drag. You could calculate the maximum energy yield from the tide's height and the orbital speed as well as the river's width and weight per unit of volume (and double that, since you get two tidal bumps for the price of one). But you need a large satellite already there.
Would it be free energy? Definitely not. The energy would come from the orbital momentum of the ( planet + satellite ) system. Harnessing this energy would mean that the planet would now present an offset "grav bump" to the satellite, resonant with its orbit, thereby siphoning off its orbital energy. The satellite would then slow down and drift farther and farther from the planet, until the planet was "tidally locked" to the satellite (looking at the planet from the satellite, you would see it stop rotating altogether).
Of course, the quantity of energy we're talking about is immense, and at the maximum possible rate of extraction - even if you filled the river with mercury and always kept the tidal bump in quadrature - it would take millions of years before a gravitational lock could occur.
I seem to remember an episode in Doctor Who where some scientist is extracting energy from some alternate Universe (?) and summons some form of creature in response. The Doctor then explains to the scientist how to tap the planet's rotational energy instead (I might misremember, though).
It flows, slowly. The power source is the tides. You could extract some energy from it but it's not a perpetual motion machine, the ultimate power source is Earth's rotation.
Extracting this energy will not slow the Earth, if you don't extract it it will be dissipated as heat instead.