There are two main reasons why people wear ear plugs. The first is to exclude sound and the second is to keep water out. The reason that it is good to stop water going in your ears often is because it can cause swimmers' ear. This condition is also known as otitis externa. This is a disorder where infection and inflammation occur. The resulting problems are itching, soreness, redness, discharge and reduced hearing. This is due to the buildup of debris, dead skin and wax in the ear canal. Wearing ear plugs for swimming prevents this from happening.
Foam earplugs are not suitable at all because they are made of sponge so absorb water and hold it close to the skin. This results in water logging and allows bacteria to penetrate into the underlying dermis. Wax and silicon putty earplugs are better than foam earplugs for swimming. Unfortunately they can only be used a limited number of times before breaking up and becoming clogged with hair and dirt. They are a particular problem for people with long hair as it tends to get caught.
Moulded earplugs from zenplugs.com/molded-earplugs/ are much more suitable for swimming because they are nonporous, last for years and can be joined with a cord so you don't lose them. Our ear plugs even contain an antibacterial compound which kills the bacteria which cause ear infections.