Historical answers have already been provided, so here's a more mechanical take.
The US has single-member districts for federal offices. Basically, whoever gets the most votes wins, and only one person wins per district (be it a House district for a Representative or a district consisting of the whole country for the president). This nature of the electoral system has a huge impact on the party system.
Duverger's law describes this impact. It consists of two parts with respect to single-member districts:
These two logics together show how the US's electoral system deeply influences its party system. The US has two big-tent parties because of the pressures inherent to an electoral system with single-member districts. Third parties are not impossible, but national success for them usually requires replacing a major party (which has happened). This preserves the number of major parties at two.
I can't tell you much about after the Civil War, but I can give you a general background on the founding of the political parties.
Political parties have an interesting history in the United States. George Washington warned against the forming of political parties at all in his Farewell Address saying "Let me now take a more comprehensive view, and warn you in the most solemn manner against the baneful effects of the spirit of party generally." Washington feared that if political parties became a common thing in American politics then the parties would stop working towards the betterment of America but rather to eliminate the other political parties. Eventually, Washington feared that one political party would gain control over the government and return America back to some sort of autocratic government, without personal liberties. In the election of 1796, after Washington's second term, political parties had already formed. The two primary parties at the time were the Democratic-Republican Party and the Federalists.
The Democratic-Republican Party was founded by Thomas Jefferson and James Madison. This party saw agriculture as America's future and was supported by farmers and rural areas. The Federalists, founded by Alexander Hamilton and John Adams, saw trade as America's future. As a result, large cities in the North tended to support this party.
The Federalist Party eventually fell from popularity after several crushing defeats in major presidential elections. However, it can be argued that the death of the party's founder - Hamilton - after his duel with Aaron Burr was a major blow to the party's leadership and helped speed up the process. Also, towards the end of the War of 1812, several Federalist leaders formed what became known as the Hartford Convention in December of 1814. The Convention made statements blasting the War of 1812 and called it un-winnable. The timing could not have been worse because just a few weeks after these statements, the war was over. This caused the Federalist party to look weak and unpatriotic. As a result it lost even more members and supporters. This pretty much marked the end of the Federalist Party, leaving the United States with one major party - the Democratic-Republicans.
Jefferson, Madison, and Monroe were all Democratic-Republicans. In the 1824 election, John Quincy Adams beat Andrew Jackson after the vote was decided by the House of Representatives. In 1828, Jackson's supporters split from the Democratic-Republican party and formed the Democratic Party to get Jackson elected. Thus, creating the Democratic Party. The supporters of John Quincy Adams created the National Republican Party in response, but it was short lived. The Whig Party was created after the National Republicans fizzled and produced several presidents. The Whigs eventually declined as well. Some former Whigs helped create a new party called the Republican Party to support of Abraham Lincoln in the 1850s.
Like I said at the beginning, I can't give much information about the parties after the Civil War. Hopefully this will serve as a good starting point for others to add to.
Source: Middle school American History teacher. As a result, this is probably an oversimplification because I am used to teaching 13- ear-olds.
For almost the entire existence of the US, there have only been two parties. But these parties have transformed over time rather than become separate entities. For example in the late 1700's, there was the anti federalist and the federalists. Then followed the democratic-republicans that replaced the anti federalists. The only time when a third party held office was the Whig party in antebellum America. Other than that, influence from third parties havent been successful (Teddy Roosevelt's Bull-moose party, or George Wallace's Independent Party). So the two party system has been around since George Washington's presidency. Hence why he warned of the two party system. The parties today are more or less off shoots of each of it's predecessors.