The British attack on the White House was about 2 years after the U.S. failed invason of Canada. So it was retaliation by the British. When ever there is an action there is a reaction it seems.
From Google:
The US tried to invade Canada in 1812, but this lead to Canadian and British forces burning down Washington, DC along with the white house.