This is a system restriction on
ContentDocumentLink. The object reference has specifics of what you're required to do:
You can't run a query without filters against ContentDocumentLink.
You can't filter on ContentDocument fields if you're filtering by ContentDocumentId. You can only filter on ContentDocument fields if you're filtering by LinkedEntityId.
You can't filter on the related object fields. For example, you can't filter on the properties of the account to which a file is linked. You can filter on the properties of the file, such as the title field.
A SOQL query must filter on one of Id, ContentDocumentId, or LinkedEntityId.
That's the one that's biting you here, and as you've discovered, there isn't a way around it. If you're aiming to remove links sharing files to specific records, for example, you'll need to do a query along the lines of
Select Id, LinkedEntityId, ContentDocumentId, IsDeleted, SystemModstamp, ShareType, Visibility
WHERE ContentDocumentId IN
('LITERAL_ID_ONE', 'LITERAL_ID_TWO', 'LITERAL_ID_THREE', ...)
The system just won't let you end-run around the requirement to filter on an Id or set of Ids by using a subquery. Oddly enough, you can subquery on
LinkedEntityId, but it's not permitted on
You can query your
ContentDocument records separately and postprocess those query results to develop a set of specific Ids you want to query against, however.
Also important to note that if you're issuing the query through some facility other than Apex with a bound Id collection variable, your
WHERE clause has a maximum length of 4,000 characters. If you have a large number of ContentDocuments whose links you would like to query, you'll need to do some batching.
I've previously shared an example of how to do this batching in a Python script.