The Bible says that God does not show favoritism toward anyone. So how is it that He favored Abel over Cain, and accepted Abel's offering while rejecting Cain's?
By saying that God is impartial (Romans 2:11), what is being said is that God doesn't favor one person over another based on external attributes. He doesn't give exceptions or passes to one group of people over another. The rich don't have an "in" with God (Matthew 19:23-25). God doesn't prefer Jews to Gentiles, which is what Paul was discussing in Romans 2. Men aren't treated differently than women. "There is neither Jew nor Greek, there is neither slave nor free, there is neither male nor female; for you are all one in Christ Jesus" (Galatians 3:28). The same rules and the same judgments are applied to every person equally.
We do the same in our courts. We want judges to make decisions based on a neutral position. When a judge decides in Sam's favor, that doesn't mean he was biased toward Sam. It meant that the judge determined that Sam acted in accordance with the law and this was accepted as being correct.
God wasn't against Cain. He even went out of His way to warn Cain that he was going in the wrong direction. "So the LORD said to Cain, 'Why are you angry? And why has your countenance fallen? If you do well, will you not be accepted? And if you do not do well, sin lies at the door. And its desire is for you, but you should rule over it'" (Genesis 4:6-7). God is stating that He uses one set of rules to decide who is acceptable to Him. There isn't one set of rules for Cain and another for Abel.
The plain fact of the matter is that Abel was doing what God commanded and Cain wasn't. Cain grew up and became a farmer. Abel became a shepherd. Somewhere along the line, God must have required sacrifices. A sacrifice served several purposes. It reminded the person offering the sacrifice about the consequences of sin. Sin brought death into the world and the death of an animal served as a frequent reminder. Sacrifices also caused a person to give a valued possession up to God. Later, under the Law of Moses, God required the Israelites to give the best lamb of their herds. They could not give a damaged or blemished lamb that did not have much value to the owner. We do not know the conditions God placed on the sacrifice, but we can see a difference in the offerings of Cain and Abel.
Abel offered the best cuts of meat from the firstborn of his flocks to God. Such an offering showed that Abel wanted to please God. Cain chose to bring some produce from his farm. The wording in Hebrew is that of a casual offering. Cain brought some of his grain when he got around to doing it. Unlike Abel, he didn't even select the first grains of his crop or the best selection from his harvest. Cain's sacrifice was not acceptable to God. Consider as well that while the vegetables were the product of Cain's labor, they could not serve as a reminder of the consequences of sin. Plants do not have life within them. Therefore, a plant does not die in the same sense as an animal or a man dies. In Hebrews 11:4, the writer said that Abel's sacrifice was better because it was offered in faith. Faith is not just a belief in God, but it is a conviction that moves a person to do what God said (James 2:14-26). Abel believed God and was obedient to him. Cain chose to sacrifice in his own way.
God laid out the same rules for both Abel and Cain. Abel followed them and Cain did not. Abel was accepted by God and Cain was rejected. We can further see the corruption in Cain because Cain blamed Abel for his rejection instead of seeing it for what it really was, a problem in himself.