Midoriko was a strong and beautiful priestess who created the Shikon Jewel hundreds of years before the time the story takes place in. Midoriko had a strange gift: She could drive out any demon's soul and purify their heart. ANY demon's heart. No wonder every demon alive wanted her dead. No one could defeat her on their own, so one day a whole bunch of demons ganged up on her.
They fought for 7 days and 7 nights, then the demons tried to absorb her soul, but she combined their souls with her own and they made the Shikon Jewel of Four Souls. The four souls are Courage, Friendship, Wisdom, and Love. Okay, now this part's really confusing: The souls of the demons and Midoriko's are still alive in that jewel, and those who use the power of the Shikon Jewel for evil and lose their heart lost it because they lended their soul to the demons inside the jewel. And when people use its power for good, they are sharing thier soul with Midoriko.
How the jewel came to be entrusted to Kikyo is another story, but I'll put it here briefly:
Sango's grandfather killed a demon who had the jewel in his possession, then brought it back to the village. He heard about Kikyo's amazing spiritual powers and entrusted the jewel to her for purification.