It appears in MacLane's 1950 paper Duality for Groups, published in the Bulletin of AMS. Of course, he is dealing specifically with the category of groups, but the definition is categorical. Section 3, titled "Free products and direct products" starts with:
"Let $A\times B$ be the direct (or Cartesian) product of the groups
$A$ and $B$, defined as the group of pairs $(a, b)$ for $a\in A$ and $b\in B$. Let $\alpha$ and $\beta$ denote the natural homomorphisms $\alpha(a, b)=a$, $\beta(a, b)=b$ of the direct product onto its respective factors. The direct product may then be described conceptually in terms of $\alpha$ and $\beta$ and the diagram [the now familiar one, labeled (3.1)] as follows. Given any group $C$, and any homomorphisms $\alpha'$ and $\beta'$ of
$C$ into $A$ and $B$ respectively, there exists one and only one homomorphism
$\gamma: C\to A$ with $\alpha\gamma=\alpha'$ and $\beta\gamma=\beta'$...
This property of the diagram (3.1) determines the direct product $A\times B$ and its mappings $\alpha$ and $\beta$ up to an isomorphism; hence it may serve as a definition of the direct product."
Similar conceptualization of the free product is given next. However, the idea already appears two years earlier in MacLane's 1948 note Groups, Categories and Duality published in Proceedings of the National Academy of Sciences of the U. S. A. According to Hall's review on MathSciNet:
"The direct product and the free product of two groups are defined abstractly in terms of homomorphisms, the two definitions being formally deducible one from the other by applying the following "duality rules'': invert the direction of each homomorphism, invert the order of all products of homomorphisms, interchange homomorphisms onto with isomorphisms into."