Cain obviously sinned or he would not have been punished by God. We must not assume that the first 9 chapters of Scripture record all that God revealed to man. Cain and Abel obviously had been instructed to make an offering.
Genesis 4:3-7 tells us of the worthiness of Cain's offering relative to Abel's:
3 And in process of time it came to pass, that Cain brought of the fruit of the ground an offering unto the LORD.
4 And Abel, he also brought of the firstlings of his flock and of the fat thereof. And the LORD had respect unto Abel and to his offering:
5 But unto Cain and to his offering he had not respect. And Cain was very wroth, and his countenance fell.
6 And the LORD said unto Cain, Why art thou wroth? and why is thy countenance fallen?
7 If thou doest well, shalt thou not be accepted? and if thou doest not well, sin lieth at the door. And unto thee shall be his desire, and thou shalt rule over him.
The New Testament sheds additional light on Cain's offering:
Hebrrews 11:4. By faith Abel offered unto God a more excellent sacrifice than Cain, by which he obtained witness that he was righteous, God testifying of his gifts: and by it he being dead yet speaketh.
Although the above Scripture does not speak of Cain as being unrighteous, by implication he was, particularly in light of Genesis 4:7. Furthermore, his offering was not accompanied by faith. The Apostle Paul in his letter to the Church at Rome tells us:
Romans 14:23. And he that doubteth is damned if he eat, because he eateth not of faith: for whatsoever is not of faith is sin.
This verse is obviously lifted out of context but even taken in context I believe it is applicable to the sin of Cain.
1John 3:12. Not as Cain, who was of that wicked one, and slew his brother. And wherefore slew he him? Because his own works were evil, and his brother’s righteous.
The above Scripture from John verifies the remarks about Cain from Genesis and Hebrews.