Masking function does not handle CASE expressions
The substring expression https://gitlab.com/dalibo/postgresql_anonymizer/-/blob/master/anon.sql#L1675 expects masking expression to be a function that ends with ). In case you want to use CASE statement the END might be omitted:
SECURITY LABEL FOR anon ON COLUMN col1
IS 'MASKED WITH FUNCTION CASE WHEN "col1" IS NULL THEN NULL ELSE anon.random_string(LENGTH("col1")) END';
The workaround is to wrap your expression in brackets:
SECURITY LABEL FOR anon ON COLUMN col1
IS 'MASKED WITH FUNCTION (CASE WHEN "col1" IS NULL THEN NULL ELSE anon.random_string(LENGTH("col1")) END)';