TLDR: President Jimmy Carter really wanted to correct an injustice. His National Security Adviser, Zbigniew Brzezinski, stated that for Carter, the process of handing over the canal:
represented the ideal fusion of morality and politics; he was doing something good for peace, responding to the passionate desires of a small nation, and yet helping the long-range U.S. national interest.
(Quoted in Strong, R. (1991). Jimmy Carter and the Panama Canal Treaties. Presidential Studies Quarterly, 21(2), 269-286.)
The Full Story: The original canal treaty was not signed by any Panamanians, but by a Frenchman, Philippe-Jean Bunau-Varilla. He was a diplomatic representative of the newly founded Republic of Panama, but had not been given the authority to sign deals on behalf of the Panamanian government.
His goal was to sell construction machinery that the French had left in Panama to the Americans, and he was happy to sacrifice the interests of the Panamanian nation to achieve that goal.
When the Panamanians arrived in Washington, they were forced to accept the terms of this treaty, which of course were very favourable to the USA. In particular, the USA gained control of the Canal Zone, a strip of land five miles wide on each side of the canal, running the canal’s whole length.
They constructed military bases on this land, including the building in which I’m sitting right now, just over the road from the Miraflores Locks. Panamanians bitterly resented the fact that, to get from one side of their country to the other, they had to cross territory that was, effectively, part of the USA.
This explains why that original treaty was resented so much by the people of Panama. In 1964, there were riots when staff at Balboa High School refused to fly the Panamanian flag. Twenty eight people were killed. This was bad for the image of the USA. People compared the wall that separated the Canal Zone from the rest of Panama to the Berlin Wall.
A lesson that some people have drawn is that if Theodore Roosevelt had not been so greedy in 1903, the USA might still have ownership of the Panama Canal today. If the original agreement had been negotiated and signed by Panamanians, if it had allowed the USA to own the canal that was, after all, paid for by American money, without granting the USA the right to colonize the canal zone, and if Panamanians had felt they were receiving a fair proportion of the profits from the canal then maybe, maybe, there would not have been such resentment over American ownership of the canal.
If the original treaty had been a fair deal between the USA and Panama, it is not so likely that Jimmy Carter would have seen any need to hand over the canal.
Ronald Reagan famously said “We built it, we paid for it, it’s ours and we are going to keep it.” That was a true statement about the Panama Canal itself, but not about the Canal Zone.
By Benjamin Murphy, lives in Panama City, Panama and posted on Quora.com