I don't have definite knowledge, but my guess is that the basic Soyuz needed to support long duration missions, while the Soviet lunar mission profile was sharply limited in time.
Fuel cells consume hydrogen and oxygen to run, while solar panels provide power for an essentially unlimited duration, but are heavy for the power they produce. Thus, there's some break-even point in mission duration -- shorter missions will be lighter if you use fuel cells, but longer ones would require enough hydrogen and oxygen tankage that solar cells would be lighter.
I believe the Soviet lunar landing mission profile had to be similar to Apollo 11: a short stay on the surface, a single surface EVA, no lingering in lunar orbit to do experiments (as the later Apollo flights did). The N-1 couldn't put as much mass into a translunar trajectory as the Saturn V, so every part of the mission would be stripped down to the bare essentials. Thus, a 7K-LOK mission would be only 8 days, as opposed to 7K-OK flights such as the 18-day Soyuz 9.
If we assume the mass-break-even duration for the Soviet fuel cell and solar technologies of that time was, say, 10 days, then going to fuel cells for the 7K-LOK would be a mass savings, and that mission design needed all the mass savings it could get.
The major hole in this explanation is the Zond/Soyuz 7K-L1. Being designed for lunar flyby missions, it should have faced similar tradeoffs, but it retained the Soyuz solar panels. It may be that such a major change to the electrical system wasn't attempted for Zond due to time constraints.