For most Christian denominations, the answer is simple. Scripture is supernaturally inspired. The people who wrote the Bible wrote exactly what God intended them to write.
See the CARM article on 2 Timothy 3:16 for a more in-depth explanation.
Also from the allaboutruth.org website:
The Bible tells us that all Scripture is inspired of God and
beneficial. 2 Peter 1:20-21 says, "Above all, you must understand that
no prophecy of Scripture came about by the prophet's own
interpretation. For prophecy never had its origin in the will of man,
but men spoke from God as they were carried along by the Holy Spirit."
1 Corinthians 2:13 states, "This is what we speak, not in words taught
us by human wisdom but in words taught by the Spirit, expressing
spiritual truths in spiritual words." God impressed man with His
message, then the individual author, using his own style of expression
based on his personal, educational, and cultural resources put the
message into words.
Romans 10:8 phrased it this way: "...The word is near you; it is in
your mouth and in your heart. . ." God communicated to the author the
content that He wanted written, and the author phrased the content
with his skill, style, mind, and language. We can be certain that,
although the very words came from each author, the message was as God
had intended and is authentic, reliable, and infallible. - See more here