Eek—that probably wasn’t the greatest feeling! To answer your question, yes, police officers can check license plates at any time for any reason. Here’s why:
Your license plate is in public view, so it is not by itself a search or seizure under the Fourth Amendment. In simpler words, it is not an invasion of privacy. Police officers, like anyone else, are allowed access to public information.
Essentially, police officers can run your plates for any reason and often might just do it out of boredom—which is likely the case in your experience.