I think one point of context worth remembering is that this story was most likely written during the Babylonian exile (i.e. during a period when the Hebrew speaking peoples were enslaved by the great state of Babylon).
This leave open two less obvious possibilities which may explain the peculiar features of the Cain and Able narrative.
First we have to consider the possibility that the whole story is 'stolen' from the Babylonian culture and then subtly altered to fit with the Hebrew speaking people's own theology. We have a clear example of exactly this happening with the flood narrative which is a retelling of the far older Babylonian myth of Utnapishtim as told in the epic of Gilgamesh. It is, then, possible that the story of Cain and Abel is also originally a Babylonian story (now lost), if so the fact Cain is not punished might make good sense because the Babylonians did not have a single God with a single perspective, rather their gods competed and had very human motives (i.e. there is no requirement they act 'justly'). This could explain the apparent tension in the Genesis text
A second possibility, one that appeals to me, is that this story is all about resentment
. We are only given one key difference between Cain and Able and this is the former is a farmer and the latter a herdsman. By the time Genesis was being written the Hebrew speaking peoples identified themselves as herdsmen and this was a major difference between them and the Babylonians whose empire was based on agriculture.
Given this the purpose of this story might be to imply that the Babylonians were 'of' Cain while the Hebrew speaking peoples were 'of' Abel; i.e. that God was on the side of the Hebrews not the Babylonians.
However as things stood during the exile the Babylonians held all the power, why did God not smite them and free his people? Perhaps it is this ambiguity (the fact that the enemies of the Hebrew Peoples were not being obviously punished by God) that is reflected in Cain's ambiguous punishment.