That argument assumes that is invertible. In the case where A and B are matrices, you can check (by considering determinants) that and (and hence their product) are indeed invertible. But in some other situations, for example if A and B are linear operators on an infinite-dimensional space, the result fails, and you can have operators which have a right inverse but not a left inverse.