Even when a person suffers pain in consequence of a thorn having entered into his hand, although it is at once drawn out, it is a punishment that has been inflicted on him, and the least pleasure he enjoys is a reward; all this is meted out by strict justice; as is said in the Scripture, "all His ways are judgement" (Deut. xxxii. 4); we are only ignorant of the working of that judgement.
It is not unreasonable to assume that the works of God, their existence and preceding non-existence, are the result of His wisdom, but we are unable to understand many of the ways of His Wisdom in His works. On this principle the whole Law of Moses is based; it begins with this principle: "And God saw all that He had made, and behold, it was very good" (Gen. i. 31); and it ends with this principle: "The Rock, perfect is His work" (Deut. xxxii. 4). Note it.maimonides