Answer:
The saying, 'to have a card up one's sleeve', derives from gambling with cards, where dishonest players would cheat by concealing certain cards somewhere on their person (often literally up the sleeve) to secretly switch into their hand to win a round.
The modern version does not necessarily mean the person is dishonest. It can mean that the person has a secret strategy in reserve, so that when they seem to be defeated, they will astound everyone by producing a winning solution.