Firstly it is a Parable of Jesus. That means that it didn’t really happen. It is a story. It is a story with a message.
Secondly, It is a story about two people, one , the Pharisee, who is a good living, law abiding, religious person who at the end of the story is not at rights with God!!! The other is lapsed in all his religious duties but at the end of the story he is at rights with God. The difference is in their prayer. The prayer of the Pharisee. I am not too quick to criticize most of the Pharisee’s prayer. Admittedly it is not the usual prayer, but most of it is very good. He thanks God that he is not grasping, unjust, adulterous like the rest of mankind. So far a possible ten out of ten !! Then he spoils the whole prayer by saying
“and particularly that I am not like this tax collector here”. This judgemental attitude causes him to not be at rights with God!!
On the other hand the Publican’s simple prayer “Lord have mercy on me a sinner” gives him reconciliation with God. This is a great teaching. Our prayer is to God, not to ourself. (The Pharisee stood there and said this prayer to himself!) Leave other people’s failings out of your prayer. Be humble about your own failings if you want to be at rights with God.