I cannot see how baseball caps could offer any significant sun protection. If airline aircraft were like fighter jets with glass canopies then I could believe the cap would give some protection to the face, but that limited protection would be dependent on the head/sun geometry being just right.
Actually the harmful UV rays that cause skin cancer and sunburn cannot pass through glass. So the glass cockpit windows in airliners (or glass canopies) naturally protects our skin from the sun. Personally I wear a baseball cap to cut down glare, and because the full fighter helmet is a bit heavy. I can do this because like most airlines in this part of the world, the airline that I work for issued it.