1590s, intransitive, "dig a covered trench toward the enemy's position," from French saper, from sappe "spade," from Late Latin sappa "spade, mattock" (source also of Italian zappa, Spanish zapa "spade"), which is of unknown origin. The transitive sense of "undermine (a wall, etc.), render unstable by digging into or eating away the foundations" is from 1650s.
The extended transitive sense (of health, confidence, etc.), "weaken or destroy insidiously," is by 1755 and perhaps has been influenced or reinforced in sense by the verb form of sap (n.1), on the notion of "draining the vital sap from," and later by sap (v.2) "beat with a club or stick."
It also sometimes is used as a noun, "a narrow, covered ditch or trench by which a fortress or besieged place can be approached under fire" (1640s). Sap (n.) in the "tool for digging" sense also occasionally is met in 16th century English. Related: Sapped; sapping.