Is it okay to wear shorts on a construction site?

If the site has a policy on clothing that does not allow shorts then you are expected to follow this rule.

Clothing needs to protect against hazards on site. The main reason for protecting the lower legs is to help guard against cuts, grazes and splinters etc in an environment where any skin damage can lead to infection. Some trades need to keep skin covered for other reasons - eg arc welders are exposed to high levels of ultra violet light that will cause skin damage.

During summer on very bright days it is important to protect against over exposure to sunlight which can cause skin cancer. Cases of malignant melanoma have increased dramatically in recent years.

During cold weather it is important to keep warm, especially when, for example, working at height where the cold can distract and lead to loss of concentration.