We call any function a linear function in its arguments. That is to say, we may write the function as

where a is some (presumably) non-zero constant.

So

Thus

In order for these to be equal we require that ba = ab. Which may/may not depend on the commutivity of A under multiplication, depending on the specific values of a and b.

This condition (ba = ab) is certainly sufficient to show that your linear f and g functions are commutative over composition, but I do not know what the necessary conditions are for this to be true for general operators.

-Dan