Palaeontologists have demonstrated that sex drove the evolution of the elaborate crests of pterosaurs along with features on other tetrapods such as the sails on the back of Dimetrodon. Previous thought had been varied, with hypotheses including temperature regulation and steering in flight (for pterosaurs). The features were too exaggerated to have been used in temperature regulation. There is one thing which can cause the evolution of features which would normally be detrimental and that is sex. Elaborate displays can be used to show superiority over other males, to battle other males, or to attract the attention of the female. See the BBC News article here for more and see if you notice my tutor's name.
I may soon have some images from the pterosaur display in London, provided I steal them from a friend.