Police officer tells man he could be arrested for wearing a hat