What does it mean when an object appears in a category's diagram multiple times? In my Introduction to Category Theory class, we were being introduced to diagrams and were told that "Each object and morphism may appear more than once in the diagram". At first, I thought that that would just be a visual aid, perhaps to simplify the picture, but it instead seems to have some actual meaning, and I'm confused as to what that meaning is. For example, take the diagram below, which we were shown in class:

We were told that this diagram commutes iff $g \circ f = \text{id}_X$. However, I thought that it would also be a necessary condition for $f \circ g = \text{id}_Y$, as those are two different paths between $Y$ and itself. I asked the professor this question, and he told me that I couldn't take $f \circ g$, as the input of $f$ was a different $X$ as the output of $g$ (this might not have been his exact response, I don't quite remember what he said verbatim). This really confused me, as I don't see how the same object in the same category can have two different properties simultaneously. Could anyone help resolve my confusion?

The problem is that your professor did not gave you a precise definition of a diagram.
One definition is that a commutative diagram in a category $\mathcal C$ is a functor $A \to \mathcal C$ where $A$ is a small category. The category $A$ is the shape of the diagram.
Your misunderstanding comes from the fact that your professor and yourself have different shapes in mind when looking at the diagram you drew.
For your professor, the shape of the diagram is the category with objects $0,1,2$ and morphisms $a: 0\to 1$, $b: 1\to 2$ and $c: 0\to 2$ (plus of course the identity morphisms). By force in that category, we have $b\circ a=c$. The diagram is then the functor mapping both $0$ and $2$ to $X$, $1$ to $Y$, $a$ to $f$, $b$ to $g$ and $c$ to $\mathrm{id}_X$.
For you, it seems that the shape is the category with the same objects and morphisms, except you add a morphism $d:2\to 0$. The diagram, as you see it, is defined as above except $d$ is mapped to $\mathrm{id}_X$ also. In that settings, the composite $a\circ d \circ b$ is sent to $f\circ g$, and $a\circ d \circ b$ is forcibly $\mathrm{id}_1$ in the shape category, so indeed the diagram yields $f\circ g = \mathrm{id}_Y$.

Basically, it all boils down to the fact that drawing a diagram without explicitly mentioning the shape is ambiguous.
