Answer: Some people claim that these caps, which have brim, are worn to protect from the light of the sun and its heat. However, these claims are not correct in reality because we find one who wears it at night. Is there sun at night? There is no sun, however it is fashion.
Next, I also advise the brothers who wear them that softening the eye to this limit such that a person is not capable of facing the rays of the sun, harms the eyes a lot. If it is said to a luxurious man, “run from here to the market”, he would tire greatly. However, a man who is used to walking and the struggle of walking would not care about it. All the strength of the body is like this also. So if you lower your eyes until you do not see the rays of the sun, then know that that is harmful upon you. So it is harmful from the medical perspective. Unless someone has an inflammation in his eyes (ophthalmia) or a sickness that worsens due to the light of the sun. For this one it is said: there is no harm [to wear a cap], although it is sufficient for him to wear medical sunglasses against the sun.
So I see that my advice to our brothers and children is not to wear that (ie. caps). Alhamdulliah with the them [ie. the Muslims] are clothing that protects the head against the heat of the sun: the ghutrah (the ‘Arab male headdress) and the Taaqiyyah (the Muslim skull cap) and in both of them is good.
[al-Liqaa ash-Shahri no. 56]
While the Shaikh mentioned the alternatives to wearing the baseball cap, it is allowed to wear a simple baseball cap that will protect one from the sun and does not imitate the disbelievers.
عَنْ هِشَامٍ ، قَالَ : رَأَيْتُ عَلَى ابْنِ الزُّبَيْرِ قَلَنْسُوَةً لَهَا رَفٌّ , كَانَ يَسْتَظِلُّ بِهَا إِذَا طَافَ بِالْبَيْتِ
Hishaam said: I saw Ibn Zubair (may Allah be pleased with him) wearing a cap with brim which he used to seek shade with when he was making tawaf around the House [i.e. Ka’bah]
[Reported by Musannaf Ibn Abi Shaybah no. 25353 with a Saheeh chain]
Some of the Scholars, like Shaikh Ahmad an-Najmi rahimahullah, were of the opinion that there is nothing wrong with wearing a cap[https://www.alnajmi.net/voices-action-show-id-1408.htm]. And this when the intent of wearing it is to protect against the sun and not to imitate the disbelievers. And Allah knows best
Faisal ibn Abdul Qaadir ibn Hassan