The Vedanta Sutras, commentary by Sankaracharya (SBE34), tr. by George Thibaut  at sacred-texts.com
34. Inequality (of dispensation) and cruelty (the Lord can)not (be reproached with), on account of
his regarding (merit and demerit); for so (Scripture) declares.
In order to strengthen the tenet which we are at present defending, we follow the procedure of him who shakes a pole planted in the ground (in order to test whether it is firmly planted), and raise another objection against the doctrine of the Lord being the cause of the world.--The Lord, it is said, cannot be the cause of the world, because, on that hypothesis, the reproach of inequality of dispensation and cruelty would attach to him. Some beings, viz. the gods and others, he renders eminently happy; others, as for instance the animals, eminently unhappy; to some again, as for instance men, he allots an intermediate position. To a Lord bringing about such an unequal condition of things, passion and malice would have to be ascribed, just as to any common person acting similarly; which attributes would be contrary to the essential goodness of the Lord affirmed by Sruti and Smriti. Moreover, as the infliction of pain and the final destruction of all creatures would form part of his dispensation, he would have to be taxed with great cruelty, a quality abhorred by low people even. For these two reasons Brahman cannot be the cause of the world.
The Lord, we reply, cannot be reproached with inequality of dispensation and cruelty, "because he is bound by regards." If the Lord on his own account, without any extraneous regards, produced this unequal creation, he would expose himself to blame; but the fact is, that in creating he is bound by certain regards, i. e. he has to look to merit and demerit. Hence the circumstance of the creation being unequal is due to the merit and demerit of the living creatures created, and is not a fault for which the Lord is to blame. The position of the Lord is to be looked on as analogous to that of Parganya, the Giver of rain. For as Parganya is the common cause of the production of rice, barley, and other plants, while the difference between the various species is due to the various potentialities lying hidden in the respective seeds, so the Lord is the common cause of the creation of gods, men, &c., while the differences between these classes of beings
are due to the different merit belonging to the individual souls. Hence the Lord, being bound by regards, cannot be reproached with inequality of dispensation and cruelty.--And if we are asked how we come to know that the Lord, in creating this world with its various conditions, is bound by regards, we reply that Scripture declares that; compare, for instance, the two following passages, 'For he (the Lord) makes him, whom he wishes to lead up from these worlds, do a good deed; and the same makes him, whom he wishes to lead down from these worlds, do a bad deed' (Kaush. Up. III, 8) 1; and, 'A man becomes good by good work, bad by bad work' (Bri. Up. III, 2, 13). Smriti passages also declare the favour of the Lord and its opposite to depend on the different quality of the works of living beings; so, for instance, 'I serve men in the way in which they approach me' (Bha. Gî. IV, 11).
359:1 From this passage we must not--the commentators say--infer injustice on the part of the Lord; for the previous merit or demerit of a being determines the specific quality of the actions which he performs in his present existence, the Lord acting as the common cause only (as Parganya does).