Although prevalence of skin condition is quite hard to be asserted due to rapid deterioration of soft tissues, observations made by contemporaries, iconographic sources, artifacts and modern scientific research can give quite decent insight into the subject.
Let's start, however from a modern overview of the issue. Although usage of the sunscreen is generally advised and the skin neoplasms are indeed dangerous condition, it should be noted that the prevalence of the latter are nowhere close to ubiquitous. In one of the studies performed in 2017 among roughly 5000 French women, it has been found that although there was a correlation between lifetime exposure to the sun and prevalence of basal cell carcinoma, squamous cell carcinoma and melanoma, these chances are not that significantly higher (adjusted odds ratio equal to 1.2-1.6) and in some cases usage of sunscreen of SPF higher than 30 may positively correlate with prevalence skin neoplasms (what can be interpreted as the higher propensity of sunscreen users to spend relatively much more time in the sun, even when we factor in the protection). Furthermore, the studies among various occupational groups show that, mutatis mutandis, the prevalence of skin cancer among people who spend a lot of time in the sun due to their occupation, i.e. construction workers is several (i.e. 4-6) times higher than among those working indoors. This difference, although significant, shows that even working in the sun, although significantly increasing chances of skin cancer, is far from surefire way of developing one. Last but not least, please note that the cancer occurrence is generally positively correlated with the age of the patients, and thus its prevalence might be higher today, when the average lifespan is notably higher than in previous centuries and thus cancer, although by all means known and described in medical literature at least since Hellenic Golden Age, could have been much rarer than nowadays.
Additionally, people who lived in sunny areas, especially those that have see a lot of maritime activity were using various form of protection other than clothing. Those living in the Mediterranean areas, like Greeks, commonly used ubiquitous olive oil to act as sunscreen. Egyptians often used paste made of lupin and rice. The latter was also a common ingredients for a sunscreen used in south-eastern Asia that often doubled as an insect deterrent. Ochre was also popular, and it is often posited that it has been used since prehistory. People in medieval Europe generally did not use such solutions (the methods were known, but they were generally popularized among upper strata of society) as clothing covering most of the skin was a norm in substantially colder climate, what, together with generally lower amount of sunlight did not call for additional protection.
UV-related neoplasms have higher chance of occurrence in people who who specifically tan on regular basis or regularly expose skin to the sunlight, what is relatively modern phenomenon. In medieval Europe people were generally doing the exact opposite, i.e.they were protecting themselves from the sun by ubiquitous garments covering most of the body, as they were pretty much aware of sunburns and tried to avoid them. There has been an extensive range of remedies against sunburn known in High Middle Ages, what has been expertly covered by u/sunagainstgold in this thread.
Peasants were usually wearing simple, practical clothes, usually consisting of a long-sleeved shirt and loose trousers or ankle-length skirt (as seen on this 15th c. miniature or this one from 14th c.) or long tunic and long stockings, as portrayed in this this one dating back to 11th century. This garments were often accompanied by hoods or wide-brimmed hats made of cloth, felt or straw to protect the face and neck during fieldwork (see this early 15th century miniature from the Bible of Borso d'Este). Scarves were also popular among women for more or less the same reason (the other issue was to prevent long hairs from getting in the way. Sure, all these measures did not protect the body from sun rays completely, but the general idea of covering as much skin as possible with light, permeable clothing was a great way to minimize chances of getting a sunburn.
Such clothing was lightweight and loose-fitting thus provided decent insulation against temperature while at the same time providing good ventilation and facilitating sweat evaporation (commonly referred to as 'breathing'). In Europe they were usually made of linen that makes durable, lightweight fabric greatly facilitating air circulation and transfer of sweat from skin to the surface of the fabric when it evaporates. In other areas, most notably Middle East and India, similar garments were made of cotton that found its way to Europe around 12th century thanks to the contacts with Muslim World. Furthermore, textiles used by most commoners were usually not dyed due to substantial cost and limited availability of the dyes and were often additionally bleached in the sun, thus being naturally off-white or light grey, what further helped in protection against sun rays. It is worth noting that people who inhabit warm, sunny regions usually cover their bodies with white loose garments to this day, with the best known example being Arabic ghalabiya or thaub ubiquitous across Middle East and sub-Saharan Africa.
On a side note, it is probable that many people living in cities of other enclosed spaces could have been underexposed to the sunlight. Examination of the skeletons found in the Basilica of San Lorenzo in Florence and belonging to the members of De Medici family shows high prevalence of rickets among them, including newborns and adults alike. This might suggest that the lack of sunlight exposure might have been severe enough to cause rickets, but the existence of some congenital condition resulting in vitamin D deficiency is also an option. It should be noted that the rickets has been known since antiquity, being described e.g. by Soranus of Ephesus and doctors in 15th and 16th observed its prevalence in northern parts of Europe, especially in England. In 1645, Daniel Whistler published in Leyden his book on the condition where he uses the name 'morbus puerili Anglorum' (English youth disease) suggesting substantial prevalence of rickets on British Isles what could have been caused to at least some extent by lesser amount of sunlight in northern, maritime climate in comparison with large part of continental Europe.
Giuffra, V. et al., Rickets in a High Social Class of Renaissance Italy: The Medici Children, in: International Journey of Osteoarchaeology (2013).
Shaath N.A., (2005). Sunscreen Evolution. In Shaath, N.A. (ed.), Sunscreens: regulations and commercial development (3rd ed.), Taylor & Francis, Boca Raton 2005.
Savoye, I. et al., Patterns of Ultraviolet Radiation Exposure and Skin Cancer Risk: the E3N-SunExp Study, in: Journal of Epidemiology, 2018; 28(1): pp. 27–33.