Morphisms in a category are typed: every morphism has a domain (source object) and codomain (target object).
In Jonatan’s question, f and g are necessarily distinguishable by the functions which map morphisms to their domains and codomains, respectively.