A "ha-ha" or "ha ha" is a landscaping term for a sunken fence, or fosse, -- a ditch either with a regular fence in the middle, or one with a sloping side that gets you into the ditch, and a vertical wall or fence on the other side that cannot easily be passed. The idea of using one was to keep animals and people out without spoiling the view of a formal garden or landscaped park with a raised fence. This was quite popular in the 18th century; the term is supposed to be French in origin but was found in Great Britain and the United States as well.

The term has several possible derivations. Webster 1913 under "haw-haw" says it's a duplication of "haw", meaning a hedge. Horace Walpole says in a 1780 essay that "the common people called them Ha! Ha's! to express their surprise at finding a sudden and unperceived check to their walk." The author of the A.Word.A.Day mailing list hypothesizes that the phrase might also derive from the garden owner's amusement when other people unexpectedly come upon the barrier.

Sources:
http://wordsmith.org/awad/archives/0302
http://www.gardenvisit.com/t/w9.htm
http://bsc.edu/~jtatter/glossary.html
http://www.ahs.org/riverfarm/rvrvirtualtour.htm
http://www.rchme.gov.uk/thesaurus/mon_types/H/69023.htm
http://www.calpoly.edu/~gnewell/ehs122/pages/part2/sld018.htm