Well, for one reason wearing sunglasses makes cops cool. It gives criminal an impression that "He is a tough guy, I had better surrender." The other reason, as far as I concerned, since cops have to go everywhere to run after criminal, they have to protect their eyes carefully. Whether in Tv show or in our real life, they have to go everywhere and our eyes are sensitive, so it's necessary to wear sunglasses.
Some cops have to work outside with strong sun lights. Wearing sunglasses could help them prevent from the uv rays and other bad sun lights. At the same time, wearing sunglasses could also make them look cool. It could improve their look to some degree. Sunglasses become more and more important in people's life now.
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.