The man who opened fire last summer on law enforcement officers in Baton Rouge, La., killing two policemen and a deputy sheriff, carried out his ambush “to create substantial change within America’s police force and judicial system,” according to a suicide note that investigators released on Friday.

In a handwritten letter that ran to a third page, the gunman, Gavin Long, said his attack was “a necessary evil” that he hoped would compel “good” law enforcement officers to confront wrongdoing and misconduct in American policing.

“Therefore I must bring the same destruction that bad cops continue to inflict upon my people, upon bad cops as well as good cops in hopes that the good cops (which are the majority) will be able to stand together to enact justice & punishment against bad cops b/c right now the police force & current judicial system is not doing so,” Mr. Long, 29, wrote in the letter, which the authorities retrieved from his car after the assault on July 17, 2016.

Near the end of the letter, Mr. Long praised certain officers by name — their identities were redacted — as well as “every other officer who stands up & protects & serves, and upholds their oath, even if its protecting the people from one of their fellow officers.”

The suicide note of Mr. Long, who was killed by the police, was included in the trove of…