First, check your Merged Manifest and look for the permission:
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />
Double-click it to open the manifest file that it comes from, and check the file path in the newly opened tab name. In my case, the permission was coming from:
play-services-ads-identifier-18.0.0/AndroidManifest.xml
Then, open Code -> Analyze Code -> Dependencies... in Android Studio. A report will be generated listing all your dependencies and their included dependencies. In the search field in the top of your report, search for "play-services-ads-identifier" and click the entry that it finds.
Now, in the right window you can see all your dependencies that include this library.
In my case it was imported by firebase-analytics-ktx.