Our Gemara on amud beis discusses the prohibition of Esnan Zonah and Mchir Kelev, a prohibition against using an animal for sacrifice that was a payment to a prostitute or a barter for a dog:
You shall not bring the hire of a harlot or the price of a dog into the House of the Lord your God for any vow; for both of them are an abomination to the Lord your God” (Deuteronomy 23:19). This verse prohibits one from sacrificing an animal as an offering if that animal was ever used to pay a harlot for her services, or if it was ever used as payment in the purchase of a dog.
The Mei HaShiloach (Volume II, Deuteronomy, Ki Teitzei 4) understands this commandment on a symbolic level. The harlot represents lust, and the dog represents anger. When offering sacrifices, or in the more personal equivalent, when praying, we are not allowed to mix in lust or anger. That is, one is forbidden to pray for objects of lust or to extract revenge upon people for individual grudges.
It seems that Mei HaShiloach holds that one is forbidden to pray for something that is prohibited. However, there are indications from other traditional sources to the contrary. The most famous example comes from Talmud Berachos (63a):
דָּרַשׁ בַּר קַפָּרָא: אֵיזוֹהִי פָּרָשָׁה קְטַנָּה שֶׁכָּל גּוּפֵי תוֹרָה תְּלוּיִין בָּהּ — ״בְּכָל דְּרָכֶיךָ דָעֵהוּ וְהוּא יְיַשֵּׁר אֹרְחֹתֶיךָ״. אָמַר רָבָא: אֲפִילּוּ לִדְבַר עֲבֵירָה.
Bar Kappara taught: Which is a brief passage upon which all fundamental principles of Torah are dependent? “In all your ways acknowledge Him, and He will direct your paths” (Proverbs 3:6). Rava said: One must apply this principle even to acts of transgression, as even then one must adhere to God and refrain from sinning excessively.
(There is an additional text according to some versions:)
אמר רב פפא: היינו דאמרי אינשי גנבא אפום מחתרתא רחמנא קרי
Said Rav Pappa, this in accord with the aphorism, “[Even] the burglar calls out to God as he is about to enter the cellar.”
What is the thief praying for, if not success is his endeavor? This indicates that while the Gemara is not endorsing sin, it is saying that the sinner when caught up in sin, can still pray for what he desires.
However, it is possible to interpret this Gemara as the thief praying that he does not get caught. It is not a sin to desire avoiding getting caught. The sinner then is not praying directly for success in robbing the vault, and could be why it is permitted. You could say, there are no atheists in cellars.
Magen Avos on Pirkei Avos (2:12, Rav Tzemach Duran, a mystic who lived from 1361-1444) is outright in allowing for the sinner to pray, during his act of sin, for success in his sin. He states:
“A sin in any which way is most repulsive. However, if a person must transgress the will of God for some expedience of the moment, he still should intend to do so with God’s will.”
(He gives examples of Aveirah Lishmah and Hora’as Sha’ah, sinning with the intent to serve God, such as Eliyahu at Mount Carmel (Yevamos 93a, Kings I:18 and Yael’s seduction of Sisera, Judges 4-5 and Nazir 23b. However, he then continues to discuss sins with no redeeming value or motive:)
“Even the burglar prays by the opening of the cellar…and even though there is no trace of mitzvah in his actions, he still should not forget God, his Maker, and call upon Him. He should try to find some aspect of this sin that could still be for the sake of Heaven, no matter how far fetched.”
He goes on to compare this to Saul, who all the while was sinning in seeking out a necromancer to access advice from Samuel beyond the grave, still made declarations in God’s name (Samuel I:22:10.). Vayikra Rabbah (26:7) comments on this: Said Reish Lakish, “To what is Saul’s behavior comparable? To a woman who was situated with her lover and swore by the life of her husband.”
There you have it, within Jewish thought, two different camps. One position is that it is forbidden for the sinner to pray for success, and the other opinion, while not endorsing the sin, encourages the sinner to pray. Perhaps these two opinions account for the two text versions in the Gemara Berachos we quoted above. The first opinion cannot abide by such a statement, that the Gemara actually endorses the prayer of the burglar. Yet, as we considered, it may be that the Gemara was referring to the sinner praying that he not be caught, instead of praying for success in his thievery. In such a case, perhaps all would agree that such prayers are permitted.