ANSWER: First, let us take a look at the scriptures concerning your question about why Cain was rejected by God.
" . . . Now Abel was a keeper of sheep, but Cain was a tiller of the ground. And in the process of time it came to pass that Cain brought an offering of the fruit of the ground to the Lord. Abel also brought of the firstborn of his flock and of their fat.
"And the Lord respected Abel and his offering, BUT HE DID NOT RESPECT CAIN AND HIS OFFERING . . ." (Genesis 4:2 - 5)
When one considers his jealousy 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.
You offer defiled food on My altar, but say, 'In what way have we defiled You?' By saying, 'The table of the Lord is contemptible.'
"'And when you offer the blind as a sacrifice, is it not evil? And when you offer the lame and sick, is it not evil? Offer it then to your governor! WOULD HE BE PLEASED WITH YOU? Would he accept you favorably?' says the Lord of hosts." (Malachi 1:7 - 8)
Cain's mental attitude was a key factor in displeasing the Almighty. 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 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. No one less than Jesus himself attested to Abel's righteousness when he was roundly chastising the Pharisees for their attitude and behavior.
33. You serpents, you offspring of vipers, how shall you escape the judgment of Gehenna? 34. Because of this, behold, I send to you prophets and wise men and scribes; and some of them you shall kill and crucify, and some of them you shall scourge in your synagogues, and some of them you shall persecute from city to city; 35. So that upon you may come all the righteous blood poured out upon the earth, from the blood of Abel the righteous, unto the blood of Zacharias son of Barachias, whom you murdered between the temple and the altar (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).