The Pentagon chief has told troops the military will ensure a smooth transition to Donald Trump and will obey the next president's "lawful orders".