Is sun the only cause of skin cancer? The answer is no. There are many, many risk factors that can lead for somebody to get skin cancer.
The risk factors will be determined, based on whether it's melanoma or non-melanoma. Melanoma is more common in people who have fair or white skin, people who have blue eyes, who have red hair, people who've had a blistering sunburn in the past, people who have an unusual amount of moles, and people who have had skin cancer in the past or have had a family member with skin cancer.
This list is significantly shorter for basal cell and squamous cell carcinomas. In these cancers, sun exposure by far is the most common risk factor. However, people with certain genetic diseases and people who have a history of radiation exposure, or people who are immunosuppressant due to liver transplants or other kinds of organ transplant will have an increased risk of basal and squamous cell carcinomas.