God knows beforehand everything that will happen. And He told these things to His prophets, who wrote them down in the Bible.
The prophecies happen because of God's foreknowledge, not because of self-fulfillment.
You can understand the reason for this in Mark 14:27. When Jesus said His disciples would all fall away, the disciples did NOT want the prophecy to come true. In fact, many of them denied that it would come true right in front of Jesus.
Peter said, "Even though all may fall away, yet I will not" (vs 29) and "Even if I have to die with You, I will not deny You!" (vs 31). "And they all were saying the same thing also" (Mark 14:31).
The psychology behind this is that no one wants to be known as a traitor to God. Which of Jesus' true disciples wanted to fail? None of them.
So none of them did anything to try to fulfill this prophecy (except for Judas who was not a true disciple). But this prophecy came true because God said it would (not because of human desire).
So prophecies happen because God is God. If God prophesied something and it didn't come true, then He is by definition no longer God, because something happened outside of His knowledge. So if that happened, God is no longer God or all-knowing.
---
Knowing something will happen does not translate to making them happen.
We cannot say that everything God prophesies will happen because God is causing those things to happen directly. Although there are prophecies where God causes prophecies to happen directly (such as Jesus coming again and bringing everlasting peace), not all prophecies happen because of direct involvement by God.
For example, the disciples falling away neither happened because God made them fall, nor did it happen because they wanted to make themselves fall.
That prophecy happened because God could foresee things.
As an analogy, we can look at a good teacher giving his students a test. The teacher taught the material all year long and at the end of the course, he tests his students to see whether they learned anything or not.
If a student paid attention to his teachings and studied for the test, he would pass it.
If a student didn't pay attention to his teachings and did not study for the test, he would fail it.
The teacher did everything he could to teach. But it depends on each student to pass or fail. The teacher's knowledge of what's on the test and even his prediction of how students would do, do not directly affect how things turn out.
So it is the same with Jesus' prophecy. Jesus is the Teacher who predicted that his students/disciples would fail the test (that is, they would stop believing for a time after the Shepherd is struck down).
He did not make them fail nor did they purposefully make themselves fail, but they failed because they were not good students at the time. When they saw their Shepherd (Jesus) struck down, they felt they had no hope left and they scattered. They did not believe Jesus' words that everything would be alright again.
However, Jesus comforted them by implying that He would not only forgive them, but would meet them again in Galilee to keep teaching them!
Jesus said: "You will all fall away, because it is written, ‘I will strike down the shepherd, and the sheep shall be scattered.’ But after I have been raised, I will go ahead of you to Galilee." (Mark 14:27-28)
Because Jesus is God, He foreknew everything that would happen.