I have watched tons of videos and read a ton of books on WW2, but I've never really seen or read about how effective those guns were at actually deterring or shooting down enemy fighters.
Once the P-51s could escort the bombers most if not all the way to their targets, were the turrets still necessary or manned?
The thing to remember, is that the B-17 and it's armament of machine guns (predominantly M2 Browning .50 MGs and occasionally M1917 Browning MGs) weren't so much a deterrent or counter towards enemy fighters as much as the formation they were flying in was.
Obviously, any kind of defensive fire is going to be on some level a deterrent against interceptors. Though a lone bomber or a group of bombers not flying in an effective formation could be easily picked off and destroyed by a group of competent and well trained interceptor pilots, as a B-17's guns (despite there being 13 of them in a B-17G) could not effectively cover every single bit of airspace surrounding it (not to mention how difficult it can be to fire from a moving platform against another moving target at 17,000 ft). To help make the bombers defensive armaments as effective as possible while keeping bomber squadrons relatively intact until they reached their targets and returned to base (as well as to help them drop as much of their ordinance on or near target as possible) the USAAF utilized and implemented what is known as the Box or Combat Box formation.
This formation allowed for an entire squadron of bombers to effectively cover one another from enemy fighters with their defensive weapons with interlocking fields of fire. This made the effective power of each bombers machine guns greater than if they had been flying solo. Granted, this was not perfect, since as you have already noted, until bomber escorts became common place towards the end of the war, losses were still quite high despite the use of the combat box formation.
Towards the end of the war, the formation was still in heavy use, despite the availability of escorts. This was mostly due to the fact that it helped bombers drop their bomb loads onto a tighter area with the rest of their squadron, without having to worry about mid-air collisions, and to prevent incidents like this from happening.
Sources: