Consider example:
Query.enforceGlobalSecurity();
Query q = new Query(Account.SObjectType)
.selectFields(new String[]{'Name'})
.lookup('Id',
new Query(Contact.SObjectType)
.selectField(Contact.AccountId));
System.debug(q.toQueryString());
q.run();
Which creates query
SELECT name FROM Account WHERE (Id IN (SELECT accountid FROM Contact WITH SECURITY_ENFORCED)) WITH SECURITY_ENFORCED
The problem is with inner join query has WITH SECURITY_ENFORCED which fails SOQL parser.
As a workaround you can disable security check for lookup query:
Query q = new Query(Account.SObjectType)
.selectFields(new String[]{'Name'})
.lookup('Id',
new Query(Contact.SObjectType)
.enforceSecurity(false)
.selectField(Contact.AccountId));