To show that a proof of the statement is not any less "trivial" for Dedekind's definition of "finite", let me show that g injective implies g surjective, and that g surjective implies g injective (assuming the axiom of choice).

Since we are told that X and Y have the same cardinality, we are allowed to assume that a bijective mapping b:X->Y of X onto Y exists.

Proof of g injective

g surjective: (indirect) assume g were not surjective, then the inverse of g restricted to the image of X under g, combined with b would give a bijective mapping of Y onto a proper subset of itself, contradicting the (Dedekind) finiteness of Y.

Proof of g surjective

g injective: (indirect) if g is surjective then, by the axiom of choice, there exists a mapping g* that maps every y of Y to a single x of the inverse image of y under g. If g were not injective, then the combination of g with g* would yield a bijective mapping of a proper subset of X onto X, contradicting the (Dedekind) finiteness of X.

Edit: Come to think of it: talk of the axiom of choice, in the context of finite sets, is a bit of overkill here. However, if you are not shy about the axiom of choice, there is no problem. - I suppose, someone using Dedekind's definition of finiteness is likely not to be shy about the axiom of choice.