The Mishna (Brachos 4:4) quotes the view of R’ Yehoshua that if a person is in a dangerous place he can daven a “tefilah ketzara,” a very short tefilah. The text of that tefilah includes the words, “… b’chol parashas ha’ibbur yehiyu tzorcheihem lifanecha.” What is the “parashas ha’ibbur?” The Rishonim explain that it means even when Bnei Yisrael are “porshim l’aveira.”
If Bnei Yisrael are doing aveiros, then how can we ask or expect Hashem to show mercy? They are not behaving in a way that deserves mercy! In the Mishnayos Oholei Shem the author uses this as a proof that tefilah is a metziyus – it functions like a law of nature. You don’t ask whether an object is deserving or not for the law of gravity to work -- it just works. In that same way, tefilah can elicit rachamim irrespective of the merits of the request.
Proof from this past week’s parsha: Chazal (Midrash Tanchuma) write that because Eisav let out a cry when he found out the brachos were taken from him, Ya’akov’s great… great gransdson Mordechai midah k’neged midah was forced to cried in pain at Haman’s decrees. Surely Ya’akov was deserving of the brachos that he received, and Eisav was undoubtedly a villain. Nonetheless, a true cry, even if it comes from an Eisav, can produce tremendous results in shamayim. (See Netziv in Harchev Davar 27:9 for a different approach.)
Another proof: In parshas Va’Eschanan, Hashem ordered Moshe to cease davening to go into Eretz Yisrael. If Hashem did not want Moshe to go, then all the tefilos in the world shouldn’t have made a difference. Why demand that he stop? Just don't listen! Again, we see that tefilah operates as a force within teva. Hashem didn’t want Moshe to go, but Hashem would not overturn teva to prevent Moshe from taking the law into his own hands.