A long-serving Conservative MP has said he will not stand in the general election, just hours after A-level students revealed he had told them that he believed “homosexuality is wrong” and “dangerous to society”.