Obviously, in certain cases, California law requires you turn your car headlights on. But when it isn't required, is it nevertheless legal to keep them on, or are there situations when it is illegal to drive with your headlights on? And if so, what are those cases?
Yes, it is absolutely legal to drive with your low-beam headlights on at any time. High-beam headlights must not be used when there is approaching traffic (within 500 feet), or when you are following another vehicle (within 300 feet). regardless the time of day or night.
There are actually several sections of road in California that are designated as "Daylight Headlight" zones, where it is recommended to turn your headlights on even during the day in order to increase visibility.
I have been driving in California for almost 10 years, and have never driven with my headlights off (at least, in my own car which turns them on automatically when the car is turned on). Leaving your headlights on helps with visibility and means you won't forget to turn them on at dusk when they are legally required.
I can't speak to California code, but I've driven my own Canadian car to California twice since daytime running lights became mandatory here (in 1989 and in 2015). Both times we spent a week or more in California; in 2015 we were about twelve days in the state (nine days in San Diego, three in the Twentynine Palms area). Nobody said a thing about my car having headlights on in the day.
On rural roads, particularly undivided highways, it's wise to have low beam headlights on, if your car lacks specific daytime running lights, because it's easier to see you at a distance.
When entering a guarded military base gate you may be required to turn off your headlights at night, so as to not "blind" the guards.
I did not find a specific law or regulation, but it is often posted on signs and customary.