Before the Civil War, there was no single day for remembering soldiers who died in war; people just did their own thing, for their own relatives. This changed in the aftermath of the Civil War, probably in part because far more people had died than in all the other wars combined. A need arose to commemorate the deaths, and in 1865 the federal government began creating national cemeteries to bury soldiers.
General John Logan, at that time the commander in chief of the Grand Army of the Republic, the Union veterans organization, called for a Decoration Day on May 30, 1868, to remember the fallen boys in blue. ('Decoration' referring to wreaths and pictures and the like decorating graves, not military awards.) It was already a tradition in the southern states, having started in 1866, but different states picked different dates, going from late April to early June.
Initially, Decoration Day ceremonies were half an excuse for bashing the Confederacy, its soldiers, and its leaders. However, it also strengthened a sense of national unity and goodwill, and by the time Reconstruction ended, the latter was a much larger part of the events than the former, frequently commemorating the dead of both sides.
Memorial Day became a more common term, first arising in the 1880s, and overcoming Decoration Day after World War II, with official recognition by President Johnson in 1967. For a century, the date was May 30, but in 1968, Congress passed the Uniform Monday Holiday Act, which moved Memorial Day, Washington's Birthday, Veterans Day, and Columbus Day to Mondays, so people would have three-day weekends. (Largely federal employees, since they're the only ones who have to get those days off, but a fair number of businesses are closed on those days as well.)
Now, we all love three-day weekends, but the VFW has pointed out that getting the Monday off is kind of missing the point of the day itself; some holidays are primarily about not working, but this isn't one of them. The original date was pretty much arbitrary, apart from being good for having flowers in bloom and not being the date of any actual battles. Donald Inouye, a WWII veteran, introduced a bill changing the date back every year, from 1987 until he died in 2012.