Answer: First, let us take a look at the scriptures concerning your question about why Cain was rejected by God. We are first informed that Abel (the youngest of the two men) was a shepherd of sheep while his brother was a farmer (Genesis 4:2).
When the time came to make an offering to God, Abel choose to bring and kill a firstborn animal from his flock. His brother Cain, however, offered some of his crops toward his worship of God (verses 3 and 4). The response both received clearly conveyed whether what they did was pleasing or not.
"And the Lord respected Abel and his offering, but he DID NOT RESPECT CAIN AND HIS OFFERING . . ." (Genesis 4:2 - 5).
Many have speculated as to why the offerings of Cain were not respected. Three factors, however, can be safely assumed as contributing to the displeasure of God. The first is the attitude of mind in regard to the offerings. The second is the quality of the offerings. The third is the worship which was not done in faith.
When one considers the jealousy of Cain toward his brother that drove him to finally murder him, a poor attitude in giving offerings to God is very plausible. This attitude was likely a factor in offering to him poor quality products rather than the very best.
There is a Scripture that indicates God's response to offerings that are not of the quality He commands.
You offer defiled bread upon My altar. And you say, 'In what way do we defile You?' . . . And if you offer the blind for sacrifice, is it not evil? And if you offer the lame and the sick, is it not evil? (Malachi 1:7, HBFV).
The mental attitude of Cain was a key factor in displeasing God. Our Father knows man's inner thoughts. The Apostle Paul's writings attest to the fact that while He may like a person who is generous, he loves those who do so out of a heart of cheerfulness and not grudgingly (2Corinthians 9:7).
In the well-known faith chapter of the New Testament, Hebrews 11, the apostle Paul makes it abundantly clear that Abel had faith in God but that, by implication, his brother Cain lacked it (Hebrews 11:1 - 2, 4). Our human nature not only can think evil and hinder us to do good works, but it can also ill dispose us toward those who reject evil and are doers of good works like Abel.
Jesus himself attested to Abel's righteousness when he was roundly chastising the Pharisees for their attitude and behavior.
You serpents, you offspring of vipers, how shall you escape the judgment of Gehenna? Because of this, behold, I send to you prophets . . . So that upon you may come all the righteous blood poured out upon the earth, from the blood of Abel the righteous . . . (Matthew 23:33 - 35).
We can acquire more of the mind of Christ, and not have our heavenly Father reject us like Cain, by constantly studying His word. If we do not do this our minds can easily be led to being deceived by the devil who is "the GOD OF THIS AGE . . ." (2Corinthians 4:4).