It's completely legal...we used to have safety/light checks as well. It's a "privilege" (not a right) to use the streets, and vehicles upon roadways are always subject to the full extent of the Vehicle and Health & Safety Codes.
The benefit is that they're more likely to catch environmentalists in their 30 year-old
oil smoking Volvos.