I read a twitter thread a couple months ago that had an interesting history of the portrayal of police in American art & media.
I recognize this is all unsourced, by the way. I can't find the thread now, and wasn't able to find articles about this.
Basically, pre-1940, the protagonists in crime novels, films and TV shows were either private detectives, lone ranger types, or former cops... never actual on-duty police officers. The reason being is that the general public understanding that the police were a thoroughly corrupted protection racket for the rich and big business meant that any media that had police protagonists would be laughed off as too unrealistic.
prior to 1940, the police in media were either shown as bumbling idiots (like the Keystone Kops) or corrupt thugs, enforcing the writ of business tycoons & protecting their interests, but definitely NOT serving and protecting the public.
In the 1930's, FDR appointed commissions to reform censorship codes of American media. I guess there were a lot of Irish Catholic priests on these commissions, who sought to improve the image of Catholic Americans in media, and so pushed to have more positive portrayals of police in movies and TV shows... Police Departments were also heavily Irish American.
So... that got the pendulum swinging one way. In the late 60's, police portrayals in media became even more decoupled from reality, with pro-police propaganda like
Dragnet "COPS," and other police procedurals airing on TV.
This article kinda picks up from that, but doesn't have the backstory prior to the 60's. I haven't found anything documenting that, other than the twitter thread I read.