The Monroe Doctrine was issued for several reasons. Spain had lost its American Empire, and there was little hope of restoring it. However, French troops had entered Spain in 1823; and attempted to restore the Spanish King. There were rumors that the French intended to also restore the old Spanish Empire in the Americas. Some consideration was given to an alliance with Great Britain to prevent this from happening; however there was still the traditional fear of "entangling alliances" with European countries. Secretary of State John Q. Adams commented,
It would be more candid as well as more dignified to avow our principles explicitly to Russia and France than to come in as a cockboat in the wake of the British man-of-war."
The British were concerned that the U.S. might attempt to take Cuba, Texas and California. Adams was afraid that any alliance with the British would necessarily entail a commitment not to do so. So, rather than tie the U.S. to the British, President Monroe followed Adams advice and issued the Doctrine. At the time, European powers paid it no attention, and commented that it was obviously for "domestic consumption." It had no standing in International Law, was only valid because of the strength of the British Navy, and wasn't even called the Monroe Doctrine until 1852.
There are a number of reasons why the Monroe Doctrine was established.
Perhaps the most important reason was that the US wanted to establish its claim to be the most important power in the Americas. It wanted to assert this as a way of saying "we are important" even though the US was not at that time strong enough to enforce their claim.
A second reason was that the US wanted to improve the chances for the spread of democracy. The US liked (of course) the idea of having more democratic countries, especially in its neighborhood. By telling the Europeans to stay out, the US was trying to protect new countries in the New World from being taken over by European monarchies.
These were the two main reasons for the formulation of the Monroe Doctrine.