Yes medical tests are mandatory if you want to fulfill the qualification required to become a pilot (or meet the qualification for become a pilot). These are essential parts of the qualifications for pilot training qualifications for commercial pilot and airline pilot qualifications.
Class 2 Medical Certificate This is needed for SPL (Student Pilot License) and PPL (Private Pilot License). It checks basic health vision (you must have good sight with or without glasses) hearing and general physical fitness.
Class 1 Medical Certificate This is more strict. Required for CPL (Commercial Pilot License) and ATPL (Airline Transport Pilot License). It tests everything in Class 2 plus heart health (ECG) lung function ears and general overall fitness. Renewal is more frequent.
A pilot has huge responsibilities safety of passengers crew navigating in changing weather handling pressure during emergencies. The pilot minimum qualification is not just about schooling or skills but also health. Without passing these medical tests you cannot get or keep your license. These health rules are part of the education qualification for pilot and the regulatory body’s rules.