On planets, a space elevator goes to (geo)stationary[0] so that the cable doesn't wind up around the planet, but you can't do that on the Moon, because luna-stationary is occupied by the Earth, which inconveniently is too massive and spinning too fast to anchor the other side of the cable. However, the L1 point is also stationery relative to the lunar surface, and is the place where the gravity of the Earth and the Moon balance out.
[0] IIRC, geostationary specifically means Earth, but there's going to be some more general term for the same idea over generic parent objects and not just Earth
Although (and I wish I could find this again), I've read that lunar He3 is so diffuse that getting it out would incidentally give us so much purified aluminium, silicon, and oxygen, that sending all that back to Earth and magnetically decelerating it on arrival would give us more energy than the He3, as would burning those ingots with that oxygen.
[0] https://www.youtube.com/watch?v=3ZteJmg1TfM (10 minute video, relevant around 4:00)
Though you could equivalently try and go for Earth-Moon L1 with a counterweight on the other side of L1. It would be significantly more unstable though.
For Luna or Mars, gravity is reduced and the required diameter is less. Maybe it would even be feasible to build such an elevator if it were above the Earth. But now you're building above an alien plant, so you trade one set of potentially insurmountable obstacles for another.
I'm not sure that that system would be unstable in human timeframes since the two would be tidally locked, although it would certainly alter the engineering stresses in ways that I'm grossly unqualified to calculate. I think a portion of the cable might be under compression rather than tension? I guess it depends on the rotational speed of the whole system.
Speaking of which, substantial amounts of energy would need to be spent accelerating the spin of the Earth/space elevator system to maintain a 24-hour day/night cycle.
However, Luna's presence would perturb the whole system, either tearing it apart with tidal stresses or being ejected from the system before that could happen.
See Isaac Arthur's video about it here: https://youtu.be/dc8_AuzeYKE?t=470