What would have happened if the third stage of Saturn V had exploded during TLI? Could the CM of Apollo 11 have safely returned to earth?
If the failure of the S-IVB third stage didn't significantly damage the Command/Service Module, and the CSM was able to separate from the S-IVB, then this is a surprisingly benign failure mode and the crew would be likely to return to Earth safely.
Firstly, note that at all times during the TLI burn, the spacecraft trajectory is an elliptical orbit with perigee close to Earth, and apogee rising toward the moon's altitude over the course of the burn.
If the failure happens early in the TLI, then the period of the orbit is a matter of hours, and a slight adjustment of course will put the CSM on a reentry trajectory; this can be done with the small RCS thrusters even if the main SPS engine of the CSM is damaged.
If the failure is later in the burn, the resulting orbit would longer, up to 6 days or so. In this case, the SPS engine can be used to slow the spacecraft, significantly shortening the orbit. The CSM has a great deal of maneuvering capability, so even if the TLI was 90% done, the CSM could cancel all the speed gained during the TLI burn!
Interestingly, the preferred option if the TLI failed for any reason was to attempt an alternate mission plan, i.e. conduct operations in low Earth orbit rather than return immediately. It's even conceivable, if the TLI had progressed far enough, that the CSM could have continued with a lunar flyby or even a lunar orbit mission. If the S-IVB exploded for unknown reasons, however, and it was unclear if there was damage to the CSM, I can imagine them cutting the mission short.
Apollo Experience Report: Systems and Flight Procedures Development talks about TLI aborts a little bit. I believe there wasn't an automated abort system for TLI (since the spacecraft was on a "safe" trajectory and there was plenty of time to decide what to do about any problem).
TLI abort was indicated if the attitude error reached 45º (!) or if attitude rates exceeded 10º per second -- which would probably be the case if the S-IVB were to explode out from under the CSM.
Almost certainly, assuming the CSM wasn't damaged. During Apollo 13, they considered (but chose not) to use "direct abort", which would have used the SM engine to return without going around the moon. A failure during TLI would have been much closer to earth, and most likely not travelling as fast.