In Luke 18:9 Jesus began speaking another parable, but this time it seems he was talking to the Pharisees, because the reason for the parable is that “some trusted in themselves and despised others.” The main characters in this parable are a Pharisee and a publican (Luke 18:10). No doubt Jesus chose these two groups, because, not only were they natural enemies, but the one group did trust they were righteous, while the second knew they were not. The one group was readily received into Jewish society, but the other was looked upon with suspicion and hate.
Obviously, the immediate reason for the parable was that some men trusted in themselves that they were righteous and despised or looked down upon others as unrighteous (Luke 18:9). However, I suspect that, because the subject of the parable is prayer (Luke 18:10), Jesus is still teaching about continuing in prayer (Luke 18:1), while offenses (cf. Luke 17:1) are made to bear upon a certain group or person (cf. Luke 18:11).
We need to keep in mind that the place in which the prayers were offered was the Temple of God (Luke 18:10), but notice how these two subjects worshiped. The Pharisee prayed to himself (Luke 18:11), which may mean that he prayed quietly. However, this may not be the case. He may have been praying aloud, and his prayer was not meant for God, but “to himself” – glorifying himself in the presence of others who stood by and listened (cf. Matthew 6:5; Luke 20:45-47).
The Pharisee may have thought he was honoring God by claiming he (i.e. the Pharisee) was not like other men. Josephus wrote: “When they (the Pharisees) determine that all things are done by fate, they do not take away the freedom from men of acting as they think fit…” From this statement we are able to conclude that the Pharisee in Jesus’ parable credited God for predestinating men to their lot in life, whether righteous or unrighteous, but the man, himself, was responsible for the sins he committed in his predestined profession. Whether or not his worldview allowed for repentance is unclear, but evidently Luke indicates the Pharisees thought God predestined a man to his walk in life.
In Luke 18:12 the Pharisee adds to his prayer a testimony of the good works he had done. He did them to be admired by the people (Luke 16:15), so, evidently, he believed God also should admire him for what he did. Notice:
“They (i.e. the Pharisees) also believe that souls have an immortal rigor in them, and that under the earth there will be rewards or punishments, according as they have lived virtuously or viciously in this life; and the latter are to be detained in an everlasting prison, but that the former shall have power to revive and live again; on account of which doctrines they are able greatly to persuade the body of the people; and whatsoever they do about Divine worship, prayers, and sacrifices, they perform them according to their direction; insomuch that the cities give great attestations to them on account of their entire virtuous conduct, both in the actions of their lives and their discourses also.” (parenthesis and emphasis mine)
Nevertheless, the context of such things need to be understood from Luke 17:7-10. That is, a servant owes his master his whole waking life. All that the servant does is owed to his master. There was no room for admiration for a man who simply did his duty. The Pharisee thought his life earned him a reward from God, but clearly, if Jesus’ words are to be considered, any good the Pharisee might have done was merely what he owed his master. At the end of the day, he is an unprofitable servant, and his master owes him nothing.
In contrast to the prayer of the Pharisee, the publican brought his sacrifice and prayed that the Lord would be “merciful” i.e. satisfied (G2433) by the blood of his sacrifice. This same Greek word is used in Hebrews 2:17 in connection with Jesus making reconciliation for men’s sins. G2433 is the verb form of the Greek word, while G2434 is its noun equivalent. The noun (G2434) is used in 1John 2:2 where Jesus is said to be the propitiation or atoning sacrifice for the sins of the world. Although the publican’s worldview didn’t know of Jesus’ sacrifice, he did understand that the animal sacrifice, which points to Jesus’ atoning work, was supposed to obtain God’s mercy for sinner. It is in this context that the publican uttered his prayer (Luke 18:13).
According to Jesus, the sinful publican’s prayer, not that of the righteous Pharisee was heard by God (Luke 18:14). The Pharisee’s sacrifice and prayer was more like that of Cain in Genesis 4:1-7. There Cain offered a meal offering for his sacrifice. A meal offering was intended for fellowship, not for admitting sin or guilt. Therefore, the sinful publican, not the righteous Pharisee left the Temple justified (Romans 3:24-25), because God declared the sinner justified as a gift of mercy, but the righteous Pharisee, who didn’t admit to sin, went away without any gift from God (cf. Matthew 6:2, 5, 16).
 Josephus, Antiquities of the Jews; 18.1.3 — parenthesis mine
 Josephus, Antiquities of the Jews; 18.1.4 “(The Sadducees) are able to do almost nothing of themselves; for when they become magistrates, as they are unwillingly and by force sometimes obliged to be, they addict themselves to the notions of the Pharisees, because the multitude would not otherwise bear them.” – parenthesis mine.
 Josephus, Antiquities of the Jews; 18.1.3