Does the sun light have to have *direct access* to fruits to make them sweet?
It would depend if the fruit has the ability to sense or capture light. This depends on chlorophyll mostly, found in cellular organelles called chloroplasts. If the fruit is incapable of capturing light, the light can still have an indirect impact by being captures on leaves, since plants circulate nutrients - this is why roots can grow without having access to sunlight.

Here's a few excerpts from the following paper (https://www.ncbi.nlm.nih.gov/pubmed/11337414):

"To date, molecular regulation of the role of light in fruit ripening has been studied most thoroughly in tomato, and available evidence suggests that light has its greatest impact on pigmentation, with apparently little effect on additional ripening phenomena."

"The green to red color transition typical of ripening tomato fruit is largely due to the developmental transition of chloroplasts to chromoplasts; as photosynthetic membranes are degraded, chlorophyll is metabolized, and carotenoids, including β-carotene and lycopene, accumulate."

In plain English, the pigment that captures and absorbs sunlight for metabolic reasons (photosynthesis) gets transformed into a pigment which absorbs sunlight for other reasons, such as 'looking tasty' or protection from ionizing radiation. Essentially the same thing happens to leaves in autumn - the green chlorophyll pigment, which absorbs the energy of the sun for the plant to grow, becomes the orange carotene, and the leaf slowly dies off. 

Interesting sidenote: biological pigments are very important molecules in ecology and in cell biology. Take a closer look: https://en.wikipedia.org/wiki/Biological_pigment

As for your question about how ripening occurs... Google would do a better job than most.