Lookup transformation doesn't match null with null. It seems to be a design issue. Please post screen print of the mapping and example with data for which you are seeing issue.
Unfortunately, it does match on Null. This is from the user guide:
The lookup condition matches null values. When an input field is NULL, the Mapping Configuration task evaluates the NULL equal to null values in the lookup.
What I have tried is using an expression in the lookup in the DST to only return if the input field is not null, but that generates an error. The expression I used is
IIF(ISNULL(input_field__c),'',(lookup( input_field__c = External_ID__c ): lookupobject__c.Id))
I also tried a filter in a mapping configuration task, but when I do that it doesn't input the rest of the data even though I have 3 other lookups in the mapping. For the lookup that is optional, I added a filter for inputfield is null and only the ID from that lookup is mapped to the target. The other lookups map the rest of the fields to the target.
You can try a similar expression in Mapping with Expression transformation, making use of un-connected lookup.
Lookup in Data Sync Task is equivalent to connected lookup, so condition based lookup cannot be done in DSS.
Well, I did try a soql filter in mapping, but then the rows are ignored. I also tried a filter transformation and then I got an error that I can't have two active transformations flow into a passive transformation.
I found the way to do this. The expression in the lookup should be as follows. With this it will insert a null value when the input field is null.
IIF(ISNULL(input_field__c),NULL,(lookup( input_field__c = External_ID__c ): lookupobject__c.Id))
I tried overwriting the field in the lookup dialog (where there is $OutputVariable) with the similar expression as you mentioned, but I get parse error. Am I missing something?
Is it possible to do this in data synchronization task?
No. You will need to do this on the Cloud Mapping Designer.