What is the function of the three witches?
The three witches are a metaphor for temptation of fate. The Witches proclaim that Macbeth will become Thane of Cawdor, and then King of Scotland. Macbeth becomes the Thane of Cawdor for recently revealing the treachery of the previous Thane. This shows that the Witches spoke the truth. However, rather than trust that fate would bring about his ascendance, Macbeth takes measures to see that the Witches' prophecies about his becoming King came true. He fell to their temptation. The Witches are actually Oracles, but because their prophecies come from Occult practice, not the Holy Spirit, they are portrayed as Witches.
This is also a variation on the stories of the Oracle at Delphi from Greek Myth. She told Oedipus' parents that he would murder his father and marry his mother. They abandoned him to die to prevent this from happening, but in so doing actually set the circumstances for him to fulfill this prophecy. He was rescued and adopted by the King and Queen of Corinth, and never knew that he was actually Prince of Thebes. When the Oracle told him what he would do, he fled Corinth and went to Thebes. Along the way he killed his biological father, defeated the Great Sphinx, and then married his biological mother just as the Oracle foretold.