An American soldier who deserted his post in Afghanistan and was captured and held by the Taliban for almost five years will not serve a prison sentence.