The commander of the prison at Guantánamo Bay has been fired seven weeks before he was to leave the job.