there's nothing wrong with your proof. basically, the equivalence class of x in X is f^-1(f(x)). in other words, we are using the function f to identify "all the x's that go to the same y".
there is a "natural" bijection between the collection of equivalence classes of X partitioned this way, and the image under f of X, f(X). so ~ in X, translates to = in Y.
(~ is an equivalence BECAUSE = is an equivalence). this construction is basic to describing many important structures in math (depending on what X,Y are, and what kind of function f is).