Can you choose whether to use a character's ability after declaring or challenging?
No, you have to use the ability. According to the rules (English Rules, p. 7):


  If one of the players is indeed the announced character, that player
  immediately uses the character’s power (which can happen outside of their
  turn).


Since they don't state "may use", it's mandatory. In your case, Player A correctly challenged Player B, as he denied the latter getting the lead, which could be disastrous if Player B has a coin-generating character (King, Bishop, etc). At least, like that, Player A can choose to swap with a player who can't win, even with the lead, i.e., he has the Spy.