WASHINGTON — President Obama set aside his veto threat and late Wednesday signed a defense bill that imposes restrictions on transferring detainees out of military prisons in Afghanistan and Guantánamo Bay, Cuba. But he attached a signing statement claiming that he has the constitutional power to override the limits in the law.