The primary reason is for identity certification purposes. When you sign in to the App Store using your Apple ID for the first time, you may be asked to provide an active credit card or other applicable payment information. Using this data, Apple should be able to determine that you are a legitimate user and that your identity actually exists. In addition, your location can be verified, which may affect which apps are available for you to download in your respective region.
In the case of free apps, downloading them shouldn’t cost you a single cent. However, these days, even free apps come with advertisements for other third-party apps and services that may incur charges. They may also come equipped with in-app purchases designed to give you extra features to enjoy. In both cases, Apple would need to have a way to receive funds from you.