"Although it is undeniably more romantic to pretend that Shakespeare either made up the plot of Romeo and Juliet or transcribed it more or less directly from his own experience (as did the popular film Shakespeare in Love), the story of Verona's star-crossed couple had been popular throughout Europe for half a century before Shakespeare's dramatization."
William Shakespeare did write his plays to make money, it was his source of income. He became famous as a result of his skilled ability to transform stories that he read into captivating plays.
As far as Romeo and Juliet, there is a theory that he read about the star crossed lovers in a poem by another author, which was not uncommon for Shakespeare to get his ideas or inspiration from the news or other works.
"an English poem by Arthur Brooke, The Tragical History of Romeus and Juliet (1562), which Shakespeare had already used when composing an earlier play with the same setting,"
"Tales of unfortunate aristocratic lovers proliferated in the Italian Renaissance: one early anticipation of the Romeo and Juliet story is that by Masuccio Salernitano, published in Il novellino(1474), but the first to use the names Romeo and Giulietta, and to set the tale in Verona against the backdrop of a feud between Montagues and Capulets, is Luigi da Porto's Istoria novellamente ritrovata di due nobile amanti(1535)."
We shall never know what he was thinking, and his intentions were never recorded. All we can go on for an answer to your question is to look to the themes. Shakespeare's themes involved young and aggressive love (lust) and how it did not last. Another theme is the lack of communication. Had they been able to communicate, they never would have ended up dead. Yet another theme would be family rivalries and the lack of passion for one another to get over their conflicts.
Today we possess all of these problems in our every day lives. We see teen love that is a bit extreme, we see gangs fight over names, and although we have the means to communicate, it doesn't always happen. Perhaps Shakespeare was trying to show us what can happen if we don't take a step back and examine ourselves.
As has been already noted, we don't really know because neither Shakespeare or his contemporaries told us.
However, we do know that Shakespeare's contemporaries loved this kind of story and they read and watched (at the theatre) many of them.
One of the favourite sources for such stories was Ovid's ancient poem 'Metamorphoses', written in the 1st Century AD by a Roman poet. In that poem there is a story of tragic love which Shakespeare would have known very well and probably used as a source for Romeo and Juliet.
Ovid's story is of the young lovers Pyramus and Thisbe, which ends with up with the young man Pyramus killing himself because he believes his lover, Thisbe, to have been killed by a lion. She has been hiding and returns to find him dying, and is so distraught that she kills herself with this sword.
We know Shakespeare loved this story because he used it in another of his plays 'A Midsummer Night's Dream'. In this play a group of simple folk act out a comic version of the story.
As I said, it seems that stories of true love destined for a tragic end were very popular at that time.
To the best of my knowledge I do not think there is a clear answer to your question. Some say that he borrowed the idea for Romeo and Juliet from the poem Romeus and Juliet by Arthur Brooks. Others say he wrote it because of his relationship with his wife Anne Hathaway, which sourred him on love.
Why did he write it? It could be to show how love conquers all, or the ramifications of a love that cannot be. I think it is up to the reader to make a decision for themselves.