Others have said it but law enforcement attracts exactly the kind of people that should not be in the profession. Cops are the bullies, hall monitors, and jocks you went to school with. The bullies enter adulthood and find that in the world outside of the schoolyard their physical size and intimidating demeanor isn't enough by itself for them to boss other people around to make them feel better about themselves. The hall monitor types just get off on the power tripping that wearing the uniform and badge gives them and are in it to abuse their power from the get-go; they just love getting all up in other people's business. The jocks graduate high school or college and find that even though they were top dog in school they are completely ineffectual in the real world, not being very bright or particularly skilled, law enforcement gives them a career path that doesn't require them to be those things while at the same time they can feel as though they are still better than everyone else. The slightly brighter ones understand that they are worthless pieces of shit, are bitter about it, and like to take out their frustration on other people.
Law enforcement jobs also attract bigots, racists, sexists, and other small-minded judgmental assholes who feel as though it's their responsibility to affect change through harassment and intimidation. Why join the KKK to kill black people when you can join the LAPD and do it legally? If women and Asian/hispanic drivers or those kids in fast cars annoy you when you're on the road, why not become a cop so you get to pull them over all day long for no good reason and give them tickets for arbitrary made-up things like "reckless driving."
There are also those who come from the military, usually underprivileged kids who joined up in the first place just to escape the shitty neighborhoods they are from. They get to the army and are trained to kill and not much else in spite of the what the ads say. The ones who aren't bright enough to make general or go on to a solid career in the private sector end their tours or get kicked out and find that their skill set includes shooting a gun and bullying people. Law enforcement for them is a natural fit.
There are also a few idealists who join up, who want to make a difference or whatever, but when they get there they find that they spend most of their time filling out bureaucratic paperwork BS, illegally collecting tax revenue for the state or their municipality by handing out pointless traffic tickets all day long, or other banal wastes of time. They're not making any big impact in the world, they work a thankless, woefully hypocritical job in a corrupt industry. They are pressured to fill quotas on arrests or tickets, to seek convictions no matter what cost there is to justice, and eventually they start losing faith and become pissed off at the world and their job. Like many of their coworkers, they start taking out their frustrations on the common man.
Add to all of that the fact that most people are assholes, both the police themselves and the people that the police have to deal with on a day to day basis. Every person's normal penchant for asshole-like behavior is exacerbated when they are in a job where they have to deal with other assholes in the public all the time. Sales associates, customer service reps, etc. Some people are cool enough that they can work these kinds of jobs without becoming callous, jaded, and cynical, but most are not.