This is a good question.
The answer is provided in the Upanishads, and elaborated in the Brahma Sutras by the Brahma Sutra commentators.
Sin and merit is nothing other than punishment and reward by Brahman (God) for actions that displease him versus actions that please him:
Kaushitaki Upanishad - For He [Brahman] 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.
Mundaka Upanishad - He whom Brahman chooses, by Him Brahman can be gained.
Grace of God is necessary for punya (merit) and even moksha. "Wrath of God" is necessary for sin.
However, why does he care so much, and if he cares so much about sin, why not prevent the sin from happening by making the world generate less naturally?
The Kaushitaki upanishad verse should answer your question. Here is also Ramanujacharya's interpretation of the verse, found in his Brahma Sutra commentary:
The text quoted, we reply, does not apply to all agents, but means that the Lord, wishing to do a favour to those who are resolved on acting so as fully to please the highest Person, engenders in their minds a tendency towards highly virtuous actions, such as are means to attain to him; while on the other hand, in order to punish those who are resolved on lines of action altogether displeasing to him, he engenders in their minds a delight in such actions as have a downward tendency and are obstacles in the way of the attainment of the Lord.
Ultimately, God desires souls to reach him, and he therefore punishes actions that are spiritually degrading, such as a Brahmana drinking liquor. And he rewards spiritually elevating actions like meditation, prayer, charity, etc.
Another reason is that Brahman guides the world process simply for the sake of his leela (amusement). In this world, there has to be all sorts of people, some good and some bad, some people who enjoy and some who suffer at various times. And so he then makes some people do good deeds and some bad deeds. However, being put into a situation where you do bad deeds is again a result of your past bad karma, and being put into a situation where you do good deeds is again a result of your past good karma, just as that Kaushitaki Upanishad verse shows.