Why did the US lose in Vietnam?

Although the U.S. committed enormous resources to the war, there was a lack of will to do the things the have to be done to win a war: go on the offensive, advance into enemy territory, seized the military initiative, and so forth. In Korea, the U.S. advanced well north of the 38th parallel at one point, although it was later forced back. The communists worried the U.S. might do this again, so they had an initiative to keep the truce.

In Vietnam, various peace treaties got signed, but the communists weren't motivated to follow any of them because they weren't worried about the U.S. advancing into Laos or north of the 17th parallel. This is because President Johnson followed a defensive strategy called "containment", partly because he worried that a decisive victory would swing American politics to the right, leading to the rise of a Douglas MacArthur-like military hero.

As the war dragged on without result, it gradually lost public support. Democrats in Congress wanted a U.S. defeat to humiliate President Nixon. These two factors resulted in the passage of the Case-Church Amendment in 1973, which ended direct U.S. involvement in the war and left South Vietnam to fend for itself. This revived the hopes of China and the Soviets, who then poured resources into North Vietnam. The result was a communist victory two years later.