In the context of medical and dental entry, the purpose of doing voluntary work is to become a more well-rounded and suitable candidate by developing the qualities and traits you’ll need to excel as a medical professional (e.g. empathy, integrity, teamwork, cultural awareness). If you possess a wide range of desirable traits, and you’ve developed these traits more than other candidates have, you’ll be able to stand out in your written application and interview and hence boost your chances of successful entry.
You can’t develop all of the traits that interviewers are looking for through school alone—you REALLY can’t, as the specific context in which these traits are applied is completely different to how they might need to apply them in a school environment—so you need to develop them through your personal life and through seeking other opportunities that challenge you in different ways, namely voluntary work and extracurricular activities.
Plus, another bonus of doing voluntary work is that it exposes you to the realities of working with people in healthcare settings (or similar). So in short: voluntary work and extracurricular activities are extremely beneficial when you’re applying for medicine or dentistry because they provide you with both exposure and the opportunity to develop desirable traits.