Generally, an autopilot will use the gray-code output from an encoding altimeter to capture the preset altitude, and afterwards will use an internal barometric sensor to hold that altitude.
There are thus two separate issues.
If the preset alt is not being accurately captured, that is down to the altimeter, the link to it, or something subtle in the AP.
If the preset alt is captured OK but is not held thereafter, the baro sensor in the AP system is probably duff. This is not unusual.