> Banks are obliged by the law to provide basic financial services (bank account and identification services if I recall correctly) to EU residents as part of the European Single Market
While offering a "Basic bank account" is a legal requirement, they have no requirement to offer that service to any specific person. In reality, it typically means that they're offered to people in debt, but not to people the bank doesn't like, american citizens, prisoners, etc.
They do have a requirement to offer basic payment account to all legal EU residents. Even to people who have no legal right to reside in EU, but whose expulsion is impossible.
From DIRECTIVE 2014/92/EU CHAPTER IV, Article 16:
2. Member States shall ensure that consumers legally resident in the Union, including consumers with no fixed address and asylum seekers, and consumers who are not granted a residence permit but whose expulsion is impossible for legal or factual reasons, have the right to open and use a payment account with basic features with credit institutions located in their territory. Such a right shall apply irrespective of the consumer’s place of residence.
Member States may, in full respect of the fundamental freedoms guaranteed by the Treaties, require consumers who wish to open a payment account with basic features in their territory to show a genuine interest in doing so.
Member States shall ensure that the exercise of the right is not made too difficult or burdensome for the consumer.
If you are legally resident in an EU country you are entitled to open a "basic payment account".
When banks can refuse you a basic payment account
You can be refused an account if you do not comply with EU rules on money laundering and terrorist financing.
In some EU countries, you may be refused a basic bank account if you already have a similar account with another bank in the same country.
If you're applying for a basic payment account outside the country where you live, banks in some EU countries may also want you to prove a genuine interest for doing so – for example if you live in one country but work in another.
While offering a "Basic bank account" is a legal requirement, they have no requirement to offer that service to any specific person. In reality, it typically means that they're offered to people in debt, but not to people the bank doesn't like, american citizens, prisoners, etc.