Could the Apollo astronauts have done an eva, from the Command Module, during the flight to or from the Moon?
They did. Apollo 15, 16, and 17 has an EVA to recover film from cameras in the Scientific Instrument Module Bay (SIMBay) on the Service Module to bring back inside.
This table, linked, shows all the Apollo EVA's.
Worden (Apollo 15), Mattingly (Apollo 16), and Evans on Apollo 17 spent about 3 hours total on EVA.
Some good articles on these deep space EVA's are here: History of Deep Space EVA
In addition to the scheduled EVAs on the later Apollo missions, if the lunar module was unable to securely dock with the command module after returning from the moon, the commander and lunar module pilot could have EVA'd back to the CM. This procedure was never required during the program. (The Soviets' tiny 1-seat lunar lander, the LK, had no docking hatch, and EVA was the normal way to get between it and the LOK mothership!)