A real prayer is considered as a disincentive to commit sin.
Question:
Allah the almighty says in the Holy Quran: "إنَّ الصلاةَ تَنهی عَنِ الفَحشاءِ وَالمُنکَر [surah al-ankabut, ayah 45]; Indeed, prayer prohibits immorality and wrongdoing" on the other hand Sometimes the people who offer the prayers commit sins then doesn't it mean that these behaviors contradict this verse of Quran?
Answer:
At first the Holy Quran says: "تَنهی" not "تمنع" it means the prayer doesn't fasten our hands to prevent us from committing sins rather warns the one who offers the prayers and proscribes him in the situation of the sin. For example, it is like Traffic signs beside the street that is just for warning.
The second point is that if the man didn't pray, of course he commits sin more?
And the third one is there is difference between prayers qualitatively. The more the prayer is perfect and complete the more it prevents us from committing sins. Anyway, the prayer of the one who offers the prayers, God willing, prevents him from sins.[1]
Note:
[1] Bihar al-anwar, v.82, p.198.