It makes sense enough, though not at first glance. Whenever Nightmare is used, the target is stored in a global variable. This global variable sticks around between games. So, the AI cast Nightmare on a GotP in a previous game. It tried to cast it again this game, but since the targeting failed, the target wasn't stored in that variable. The game still thought the targeting succeeded though, so it filled TorB's hand with copies of the card stored in the variable anyway.