Universities will have to roll out codes of conduct to protect freedom of speech, the Education Secretary has said.