It is true that some of them are wearing sunglasses for cool.However, for most of them, especially those patrol cops wear sunglasses from protection themselves against ultraviolet rays. When they are patrolling outside, they are exposed to sunlight excessively and this exposure last for a long time every day. Therefore, they have to wear sunglasses to protect their eyes.
In addition, sunglasses can reduce glares and make the vision clear when the police officers are driving their motorcycles or their cars.
Lastly, sunglasses make cops look more intimidating, or at least they think sunglasses will do.