If you have activated voicemail, people can leave you messages according to your privacy settings.
By default, your privacy settings allow anyone to call you, and so anyone can leave you a voicemail. If you update your settings so that only your contacts can call you, then only your contacts can leave you voicemail.
Learn how to control who can call you.