Earplugs are meant to block out noises, but will not completely prevent you from hearing loud sounds such as a smoke detector or beeping alarm clock or blaring horn. So in that respect, it is safe to wear earplugs to bed. As far as the health of your ear goes, studies show that long-term use of foam earplugs can cause earwax to build up or become impacted. Earplugs block the outward flow of earwax that is naturally produced so that ears are self-cleaning. Foam plugs are often pushed in too far, which can also pack the wax deep inside your ear canal, and possibly against the eardrum. You may end up with tinnitus (constant ringing of the ears), pain, or hearing loss. And you should also keep in mind that it is easy for bacteria to thrive on warm, moist, foam earplugs, so it's quite easy to get an ear infection with extended use. Using store-bought foam earplugs that don't fit your ear perfectly can also irritate the skin, another cause of infection.
If a pillow over your head won't do the job at night, instead of dealing with the risks of impacted earwax or infections, try using a white noise machine on your nightstand to drone out the noises that keep you awake. Save the earplugs for blocking out disturbing sounds that are short-lived and temporary— when you want to cat nap on a plane or a construction project outside your office window is wreaking havoc on your concentration.