What do you get when you combine a nationwide identity crisis, the collapse of the Spanish empire, and imperialist ambitions all around? Well, you get one of the most influential speeches in American political history.
Before 1823, the United States had followed a neat little pattern: America tried to be taken seriously, but also not get involved in European affairs. After all, Europe was the stuffy Old World that they had fought to get away from, where they still had kings and peasants and such.
The problem was the U.S. kept getting pulled into international affairs. Ugh, the perils of being a nation. You're going along, minding your own business, and suddenly—bam—you're fighting in a maritime war.
The culmination of American frustration with Europe was the War of 1812, which was caused primarily by Britain's violation of previous agreements on proper maritime behavior. (Here's a tip: if you want to get along with another country, don't kidnap their sailors.)
There was mixed support for the war, but a lot of people were still pretty anti-British, including John C. Calhoun, a member of Monroe's cabinet. Before the war, Calhoun was a member of the "War Hawks," a group of new congressmen who were really rooting for war with their former colonial overlords.
They got their wish, but the war didn't really accomplish much, unless you count burning down the White House and writing of the The Star-Spangled Banner. (Source)
Once the war was over, America entered a brief "Era of Good Feelings," during which there was only one political party and everyone skipped through daisy fields together singing "Kumbaya" (allegedly). That's the country Monroe inherited when he was elected in 1816.
It didn't last long.
Americans became increasingly worried that European countries were going to try and establish more colonies in the Americas. They weren't totally off-base. In 1821, Russia claimed control of the western coast from Oregon to Alaska, and a bunch of independence revolutions in Latin American countries led to rumors that Spain would try to re-conquer those areas. (Source)
Of course, most of the rumors and fears were totally wrong. European countries weren't plotting to carve up the New World. (Source)
Although given past colonialism and the Scramble for Africa later, it's really not that crazy to worry about such a thing.
Although American relations with a ton o' European powers were strained, the American-British relationship was particularly complicated. The British Empire was the fastest growing empire in the world, which led to some uneasy feelings over on the North American Continent. But we were still tied to merry old England: the United States had never really escaped from Britain's cultural influence. (And everyone, even then, thought British accents were super-cute. (Source)
And, on the plus side as far as we were concerned, Britain was staying away from major imperial alliances with other European countries. Also, in 1823 their foreign minister George Canning actually tried to get Monroe to agree to an alliance, to prevent other European powers (a.k.a. France and Spain) from trying to snatch more colonies in the New World, which would cut off Britain's shiny new markets and undo all that pesky work they had done to kick out France in the 1700s. (Source)
James Madison and Thomas Jefferson were on board with Canning's plan, but John Quincy Adams was decidedly not. In the end, JQA was the victor and Monroe refused Canning's offer…because it didn't really jibe with our whole "independence" shtick.
Around the same time American leaders were all flustered about European imperial aspirations, they were also starting to expand the American empire. (Apparently, it was totally fine when the U.S. did it.)
In 1819, the U.S. got Florida from Spain, alligators and all, as a result of what's known as the Seminole War (1817), where a young Andrew Jackson "creatively interpreted" his orders and basically invaded Florida. (Source)
That's a long story that you can enjoy at your leisure, but for now it just means that the U.S. was already starting to, let's say, forcibly collect former European colonial land. It's kind of like Monopoly, except you don't really go to jail and you have to evict the previous population before you can build your hotels.
Also, you didn't get to play with an adorable little Scottie dog piece.
So what Americans were experiencing in 1823 was a country that was trying to get out from under the influence of Britain, recover from the War of 1812, add land from former European colonies, and also prevent European countries from adding new colonies in the New World. Phew, that sounds like a lot on America's plate.
Enter James Monroe and John Quincy Adams, who decided it was time to take an independent stand against (mostly nonexistent) European colonial aggression.
In reality, the U.S. didn't really have the military power to back up the Monroe Doctrine at the time. It was really more of a symbolic statement than a legitimate threat. In other words, it was a "pay no attention to the man behind the curtain" sort of situation. People took notice, though, and throughout the 19th century the idea definitely got real as the U.S. got stronger.
Monroe's speech was generally inspired by years of concern about European encroachment on the Americas, as well as America's own ambitions of being the boss in the New World. Oh, and all those independence movements in Latin America: those were pretty important too.