In my studies on creative writing, I've found dozens of people who say:
"You should never write to make money, but you should do so because it is your passion."
There is a lot of truth in that. After all, if you were to write JUST for the purpose of making money, your writing would probably suck.
I know a lot of writers who basically just write whatever is popular at the time, all for the purpose of cashing in on hype in order to sell a few more books. Immediately after 50 Shades of Grey struck it big, dozens of softcore BDSM novels hit Amazon's virtual shelves. These books were written by people who just wanted to make money, and it worked--sort of.
The writers who capitalize on hype may sell a few books, but they never truly become the next Brandon Sandersons, Danielle Steeles, John Grishams, Stephen Kings, or Tom Clancys. They are the ones who make other indie authors and publishers look bad, as their books are usually poorly-written, poorly edited, and just look like all hell.
In this case, it's ALWAYS best to avoid writing on a topic just because it's popular. In the wake of Twilight, thousands of vampire books were published. Zombies have become popular thanks to The Walking Dead. Good authors will write what they are writing not because it's popular, but because it's the story bursting out of them.
However, I love pointing out the flip side, and there is definitely a big "but" to this one…
If you NEVER write to make money, you're going to accomplish exactly that! You may be passionate about your story, but there's no guarantee that readers will be. Take a look at Dinosaur erotica. I'm sure the writers wanted to capitalize on whatever weird trend was going on, but it's mocked relentlessly and has probably sold VERY FEW copies.
You can't make your writing so odd and your theme so obscure that no one will buy it. You have to cater to your audiences at least a bit in order to write good stories. There has to be a proper balance to your writing, and writing with your readers in mind is the best way to ensure that your story--while it is your own and unique to you--will sell enough copies to put some food on the table!