In chess programming, the program is usually tasked with finding the "best"" solution in the given position.
If there is no way to win, then the best solution is the one that makes it harder for your opponent to win; i.e. usually the longest path to victory. Or, if a draw is possible, the computer will keep playing for that draw. most programs today have some mathematical algorithm for evaluating positions. (Those numbers which roughly correspond to the 1 pawn=1 point system.) Computers are not capable of feeling things like despair. So if it evaluates two paths and finds itself losing by 9.57 points in the first and 9.45 in the second, they'll choose the -9.45 path. They may be programmed to resign past a certain disadvantage, but if not, they'll just keep going with the best (or less worse) option.
So if a computer analyses a position and finds no path to victory, it will hanker down and make the victory of the opponent as difficult as possible. (Which incidentally is how the Soviet masters said a human should behave in this kind of position). If the computer sees a mate in 7 against itself, it will take the path that takes 7 moves, as opposed to one that hastens defeat.
Should the human opponent make a mistake, as they often do, the computer could very well end up on top again.
If you think a "won" position is easy to win, pick up a book of grandmaster games... Go up to a point where the author claims there is a clear advantage for one of the players. Now play the "winning" side against the computer. If a grandmaster hasn't yet resigned in that position, I'm guessing there's still plenty of headache in it.