Hamilton was born in Boonsboro, Maryland, and received early schooling from a local tutor named John Brown. He went on to attend Hagerstown Academy, and later Jefferson College in Canonsburg, Pennsylvania, from 1836–1840. After college, Hamilton studied law with former Maryland Congressman John Thomson Mason, Jr., and was admitted to the bar in 1845. He then commenced law practice in Hagerstown, Maryland. In 1846, Hamilton was elected to the Maryland House of Delegates, but failed to win re-election in 1847. He was, however, elected as a Democrat to the Thirty-first, Thirty-second, and Thirty-third Congresses, serving from March 4, 1849 – March 3, 1855. While Hamilton was in Congress, even though his district was largely manufacturers and miners, he supported tariffs but only as a source of revenue for the government. Other actions while in Congress included his tenure as chairman of the Committee on the District of Columbia during the Thirty-third Congress. From 1855 until 1868, Hamilton avoided politics and resumed the practice of law and farming in Hagerstown. During that time, he became widely known throughout Western Maryland as an excellent trial lawyer.
United States Senate
After his long absence from politics, Hamilton was elected as a Democrat to the United States Senate by the General Assembly, and served from March 4, 1869, to March 3, 1875. Hamilton was a strong supporter of restoring southern sovereignty following the American Civil War, but voted against the Fifteenth Amendment to the United States Constitution which granted voting rights to all men regardless of race. In 1871, Hamilton endorsed William Pinkney Whyte during the Maryland governor campaign, but regretted the decision thereafter following Whyte's actions as governor. In 1874, Hamilton was abandoned by the state Democratic Party during the nomination process for his senate seat, and was not considered by them for re-election. Instead, Hamilton ran for governor in 1875, but lost his party's nomination to fellow Democrat John Lee Carroll.
Governor of Maryland
After failing to receive nomination for governor, Hamilton again stepped away from the political arena, returning to his previous engagements in Western Maryland. During that time, however, he continued to push persistently for a Democratic nomination as governor of Maryland, which he succeeding in doing in 1879. Hamilton faced future U.S. Postmaster General, Republican James Albert Gary, during the election, and defeated him by more than 22,000 votes. As governor, Hamilton regularly conflicted with the state legislature, believing they were neglecting the state's economy. He sought to reduce government waste by abolishing excessive offices and positions, such as the office of Weighers of Grain and Hay, but again the legislature refused to cooperate with his program. He retired as governor on January 8, 1884, retaining popular support throughout the state. His hostile treatment of the legislature as governor, however, had made the state Democratic party again unreceptive towards him. Hamilton returned to Hagerstown where he avoided further involvement in state and national politics. He returned to the practice of law, but also worked to improve the city and countypublic works, streets, and water supply. He was maintained a great deal of popularity in Hagerstown and the surrounding areas, and his death following a long battle with illness was widely mourned. He is buried in Rose Hill Cemetery. His daughter Josephine married the inventor Hiram Percy Maxim. His daughter Clare married Hayden Eames, brother of the opera singerEmma Eames. His granddaughter was actress Clare Eames, his great-granddaughter is actress Jennifer Howard, and his great-great-grandson is actor Tony Goldwyn.