In some card games, the joker is a card that beats everything else, is not one of the suits - and playing it is often unexpected. In the metaphorical sense 'playing the joker' means to do something unexpected, that suddenly turns the situation about.