Fun question, although the explanation could've been clearer. For anybody still confused:
For NULLIF, the first expression determines the data type. So in this case, everything is being implicitly converted to int since the 0's and 1's are interpreted as int data type.
CAST('0' AS int) and CAST('' AS int) both return 0, so the 4 expressions are equivalent to:
The NULLIF function returns NULL if the 2 arguments are equal, otherwise it just returns the first argument. The first and third expressions are clearly equivalent expressions, so return NULL. Since (0 = NULL) does not evaluate to true (it evaluates to NULL), the 2nd and 4th expressions return the first argument instead of a NULL.
NULLIF is one of those functions that people who aren't familiar with it look at it and say "Why would anybody ever want to do this?" However, the use case I like it for is avoiding divide-by-zero situations. Rather than having conditional logic, you can divide by NULLIF(@var, 0) so that instead of dividing by 0 and throwing an error, it divides by NULL and returns NULL. From there, you can wrap the entire expression in an ISNULL if you want, or just recognize that a NULL value in your results could indicate dividing by zero.