To the various Prophets that God sent for people's guidance, He revealed His teachings. The Prophets made this revelation public, and their followers wrote it down, and passed it to subsequent generations. This is how we come to have the 'scriptures' or 'holy books' of various religions today.