If this is a recurrent issue, it might be worthwhile having it checked out by your primary care doctor
. I say this because they'll quickly be able to tell what these "pimples" are with a physical examination. It is hard, on the other hand, to make a firm diagnosis over the internet without being able to take a look.
It is certainly possible that these are pimples, which can occur basically anywhere on the body. Another possibility is an ingrown hair, if these are occurring in the general pubic area where hairs are present (as opposed to the shaft of the penis).
There are also small oil glands that are common in some individuals on the penis. These are called Fordyce spots, and they are often mistaken for pimples, but in fact are completely normal and don't require any treatment.
Finally, certain viral skin infections, especially an infection called moluscum contagiosum may cause pimple like spots o the penis.
The bottom line is to have your doctor take a look the next time you notice these spots and it is convenient for you to be seen. They'll be able to give you a firmer answer on what they are.