First, I think that the Shadow Temple was used as a prison during the Hyrulean Civil War that started (in my opinion) forty years before the events of Ocarina. Thirty years after the start of the war, it ended shortly after Link was born and left in the care of the Deku Tree. Link was about ten when OoT began.
On the topic about Bongo Bongo, I believe he was a man who lived in Kakariko above the well. He was a warden- type person in the Shadow Temple. He built the torture chambers and cells below his house and added a tunnel to go to the Shadow Temple quickly (by the events of OoT the tunnel has been closed off by the Sheikah). He also created the Lens of Truth and issued them to guards at the prison so they could see through the traps and avoid the toils people without it would have to go through.
Eventually, it was discovered that the man was a spy for the enemy tribe(s) in the Civil War. As punishment, he was given a very slow and painful death. First, his lower body was chopped off (possible explanation as to why BB has no legs?). The Sheikah worked their magic to keep him from bleeding out as they continued. Next, his hands were severed and, finally, he was beheadded.
The Sheikah discovered the tunnel going back to his house and the torture chambers, and it was consequently sealed off. Next, his house was torn down and a well was built. Impa sealed the traitor's spirit at the bottom. All the Lenses of Truth were ordered to be destoryed, but someone saw the possible benefits and kept one for himself.
Although, now that I think about it, that seems like a pretty good idea for a fanfic...