The situation you describe is not contradictory: you can take $A$, $B$, $f$, $X$ and $Y$ all empty. If any of these sets is non-empty, then you get a contradiction. Your argument is assuming that one of the sets is non-empty, but there is nothing in the statement of the problem to justify that assumption.