Deputies who responded to Kobe Bryant's helicopter crash site and took pictures of the remains were given a secret way out without repercussion ... TMZ has confirmed.

Law enforcement sources tell us ... in the days after the crash, top brass at the department was aware some of their lower-level deputies had snapped shots of the scene as well as of the remains found, and were showing them to people in and out of the department.

We're told a message was relayed to the Lost Hills substations and possibly others as well ... if you got Kobe pics -- come in, come clean and delete them. Do that, and you won't be punished. That's essentially the directive we're told was handed down by commanding officers.

What's even more concerning is the fact our sources say this attempt to get rid of the damning evidence was all being done on the hush-hush, and it was only when the L.A. Times came around asking about this scandal that the department launched a formal inquiry.

We've learned the Sheriff's Dept. learned that some deputies took pics of remains days after the crash ... this after a sheriff's trainee went to a bar and thought he could impress and pick up a woman by showing her the photos. Sources say a bartender overheard this and was so irate, he contacted the Sheriff's and lodged a formal complaint.

It's clear ... the Sheriff's Dept. kept everything under wraps until it became obvious its cover was about to be blown.

On Friday, the department issued a statement saying, in part, that top dog Alex Villanueva was "deeply disturbed at the thought deputies could allegedly engage in such an insensitive act." They go on to say, "A thorough investigation will be conducted by the department, with the No. 1 priority of protecting the dignity and privacy of the victims and their families."