Many free apps will require a card be present on the account even if the app itself is free.*
The advice provided in a previous post is minimal and not completely accurate. For example, if you are a Family Sharing member and not the Organizer, you cannot have any cards present. If one of your cards is not working, Apple will just keep on trying the others until it finds one that does work. This is presuming you do not have any account balance, otherwise in many cases it would have tried that first before trying any cards.
Read this document about how to view your current payment types and add Apple Account payment methods on an Apple mobile device, a Mac, or a PC --> Add a payment method to your Apple Account - Apple Support
If an item appears in red then it is no longer working and you either need to replace it or get it working again. Even if an app is free, Apple may require the presence of a valid payment method such as a card. You won't be charged but the card has to be there and in working order.
It is possible that none of your cards are working. You do not tell us what the exact error message says (please do not provide an image unless it is in English). If you can't add a payment method, check Add a payment method to your Apple Account - Apple Support , or this one about what to do if your payment method is declined in the App Store or iTunes Store —> If your payment method is declined in the App Store or iTunes Store - Apple Support
* Ref.:
Add a payment method to your Apple Account - Apple Support
"To make purchases from the App Store and use subscriptions like iCloud+ and Apple Music, you need at least one payment method on file." Note that there may be a differences between “purchasing” an app for money, and simply “getting” one for free. I get free ones with no payment method.
If you can’t download or update apps on your iPhone or iPad - Apple Support
- "You might need to have a payment method on file, even if the app that you want to download is free."
If you can’t download or update apps on your iPhone or iPad - Apple Support
- If you have any active subscriptions, you must have at least one payment method on file other than Apple ID credit.
- You might not be able to remove a payment method if you have a balance due.
Sign in to your Apple Account on the web or in your device settings - Apple Support
- "When you sign in to the App Store and other media services for the first time, you might need to add a credit card or other payment information."
How apps, content, and subscriptions from Apple are billed - Apple Support
- You can’t charge gifts to your Apple ID balance. If you send a gift or gift card, your primary payment method is charged.
- Some subscriptions might not be charged to your Apple ID balance.
What you can buy with your Apple Gift Card or Apple Account balance - Apple Support
"Some purchases might require that you have a credit card on file, even if you use your Apple Account balance to make the purchase."