Lang mentions in his graduate algebra textbook that commutativity can make sense in the context of a map involving $S$ and $T$:
$$S \times S \rightarrow T$$
in that $xy = yx$ can possibly hold true (I think I am understanding that right), i.e., a situation more general than a monoid law of composition. He goes on to suggest that the reader should think about the most general combination of sets for which associativity can work.
I don't really understand what he's getting at here, and I was trying to formulate it. Given sets some sets $A$, $B$, $C$, $D$, $E$, and $F$, there may be mappings $A\times B\xrightarrow{f} C$, $C\times D\xrightarrow{g} E$, $B\times D\xrightarrow{h} F$, and $A\times F\xrightarrow{i} E$, then the following compositions could make sense:
$$(xy)z = x(yz)$$
where $x\in A$, $y\in B$, and $z\in C$.
I don't know if I am getting what the author is saying.
Reference: Google books highlight
Yes, that seems to be what Lang is saying. Given sets* $A,B,C,D,E,F$ and functions* \begin{align*} f : A\times B&\to D,\\ g : B\times C&\to E,\\ h : D\times C&\to F,\\ i : A\times E&\to F, \end{align*} then we might say a generalized associativity for the above data holds if for any $a\in A,$ $b\in B,$ $c\in C,$ $$h(f(a,b),c) = i(a,g(b,c)).$$
More succinctly, we can summarize by saying that the following diagram of sets commutes: $$ \require{AMScd} \begin{CD} A\times B\times C @>{f\times \textrm{id}_C}>> D\times C;\\ @VV{\textrm{id}_A\times g}V @VV{h}V \\ A\times E @>{i}>> F. \end{CD} $$
You could also formulate similar "higher associativity" statements for "products" of four or more elements, although the diagrams you need to commute become increasingly more cumbersome...
*Feel free to replace "sets" by "objects in some category" and "functions" by "morphisms" everywhere. Of course, if you do, you can't use the element-wise description of this generalized associativity.