Many authors choose to write what they enjoy reading. Reading is the best way a writer can learn; it helps them find out what else is out there and what works, as well as discovering hidden tricks of the trade. In addition, choosing to write in the genre that they are surrounded by could be a comfort barrier to debut authors. It is what they know, it is what they feel comfortable with. And there is nothing wrong with that at all!
Sometimes though, an idea will spark in your head that is completely outside of your normal genre and comfort zone. For example, a horror author could suddenly write a crime novel (remember Stephen King and 'Mr Mercedes'?) or a fantasy author could choose a romance title. Inspiration can lead to some really unique work, so do not hold it back; set it free, like a bird.
In the early stages of their writing careers, authors can traverse a number of genres. There are many reasons why this might be the case - each author is different of course - but there is one that is common for a number of them; authors, most of the time, write from their hearts.
If you have an idea that does not seem to fit in with your normal genre or style, do not suppress it. If your heart is telling you to write it, take note of what it is saying. You might be surprised at the results.