Robert Gates, the US defense secretary, has criticised a court ruling that would end the ban on gay personnel serving openly in the armed forces.