Cedar wood has naturally occurring chemical extractives, and because of these chemicals cedar is very durable and weather resistant. Unfortunately these chemicals dissolve quite easily in water. Stains around nails or screws are caused by a reaction between the iron in the nails or screws and the chemical extractives from the cedar.
When painting cedar, it is crucial to use a primer so water isn’t given the opportunity to enter the cedar and break down the chemicals. Since you don’t use a primer when staining, it is highly recommended to use hot-dipped galvanized or stainless steel (if they have the right chromium concentration) nails/screws. When painting cedar you should use these nails/screws also. These nails and screws do not have the same reaction with the chemical extractives that iron or regular galvanized nails/screws do.