If you violate the law or an ordinance, you may be cited for it. The officer citing (whether a police officer, sheriff, park ranger, etc.) has no legal obligation to inform the person that they will be or intend to cite; they can simply issue the citation. They can take ID for verification of identity then decide to issue a citation--they do not need to warn you in advance that they may do this. What you describe is legal.