The error usually occurs if you missed creating Application user by adding Application ID
of Azure AD application.
I registered one Azure AD application and granted API permission like this:

Now, I generated access token using client credentials flow via Postman with below parameters:
POST https://login.microsoftonline.com/<tenantID>/oauth2/token
grant_type:client_credentials
client_id:<appID>
client_secret:<secret>
resource: https://orgxxxxxx.crm.dynamics.com
Response:

When I used this token to run below sample API, I got same error as you like below:
GET https://orgxxxxxxx.crm.dynamics.com/api/data/v9.2/WhoAmI
Response:

To resolve the error, you need to create one Application user by adding Application ID
of your Azure AD application.
Go to Power Platform admin center -> Environments -> Select your organization -> Settings -> Select Application users

Now, click on New app user
option to create Application user like below:

Enter your Azure AD application name or ID in search bar and add it like this:

Now, select your organization under Business Unit
and make sure to assign System Administrator role to create application like below:

After creating application user, I generated token again and got the response successfully when I used it to run sample API like this:
GET https://orgxxxxxxx.crm.dynamics.com/api/data/v9.2/WhoAmI
Response:

In your case, make sure to create Application user by assigning proper role following the above steps.