Because in 2nd case you adding same reference twice and HashSet have check against this in HashMap.put() on which HashSet is based:
if (e.hash == hash && ((k = e.key) == key || key.equals(k))) {
V oldValue = e.value;
e.value = value;
e.recordAccess(this);
return oldValue;
}
As you can see, equals will be called only if hash of key being added equals to the key already present in set and references of these two are different.