The United States has for several years been secretly releasing high-level detainees from a military prison in Afghanistan as part of negotiations with insurgent groups, a bold effort to quell violence but one that U.S. officials acknowledge poses substantial risks.