Yes. Sunglasses are necessary for pilots when flying. The UV rays are so strong because the thin athmosphere doesn't work too well in filtering the UV rays. So pilots should wear sunglasses when flying to protect their eyes from harmful UV rays in case their eyes get damaged by the strong sunlight and UV rays. Besides sunglasses can help them adapt to darkness more quickly when they fly at night. However, pilots shouldn't wear polarized sunglasses because the windshields of the airplane is polarized, which would interfere with the polarization of sunglasses.
I don't think it is necessary. Some pilots don't wear it. Of course, there are some pilots do wear sunglasses during the day. Sometimes even on the ground. Anyway,Sunglasses are not worn to be cool, sunglasses are also worn for shield eyes from extremely bright sunlight at altitude, thus to reduce the rate of things like macular degeneration later in life. So, it is a wise choices of wearing sunglasses while flying.
Personally I think it is necessary. Sunglasses are important for everyone, but especially for pilots. The atmosphere protects the earth from much of the sunâ€™s harsh radiation. Airplanes fly in the upper levels of the Earthâ€™s atmosphere and are exposed to much higher levels of solar radiation. Exposure to UV rays increases 5% for every 1,000 feet of altitude. Pilots need to wear sunglasses to protect their eyes from the sun, to help them effectively fly and to provide an added layer of protection should something happen to the plane. For example sunglasses might protect a pilotâ€™s eyes from debris if a bird were to hit the windshield.