The gemara brachos 60a asks how could Leah daven for her fetus to change genders if the mishna calls that a wasted tefilla. The gemara gives 2 answers.The first is, acts of miracles are different. I don't understand what this answer is saying. The mishna seems to be saying one can't daven for a miracle.
Let’s look at what precisely the Mishnah had said:
והצועק לשעבר הרי זו תפלת שוא היתה אשתו מעוברת ואומר יהי רצון שתלד אשתי זכר הרי זו תפלת שוא היה בא בדרך ושמע קול צוחה בעיר ואומר יהי רצון שלא תהא בתוך ביתי הרי זו תפלת שוא
BUT TO CRY OVER THE PAST IS TO UTTER A VAIN PRAYER. IF A MAN'S WIFE IS PREGNANT AND HE SAYS, [GOD] GRANT THAT MY WIFE BEAR A MALE CHILD, THIS A VAIN PRAYER. IF HE IS COMING HOME FROM A JOURNEY AND HE HEARS CRIES OF DISTRESS IN THE TOWN AND SAYS, [GOD] GRANT THAT THIS IS NOT IN MY HOUSE, THIS IS A VAIN PRAYER.
(Soncino translation, capitals in original)
The Mishnah seems to be stating a general rule, and then giving two examples of how that rule would apply in practice. The general rule is that you can’t pray for something that has already happened. The two examples of things that you can’t pray for because they have already happened are the sex of your unborn child and the who the victims in the town are.
Thus far we have seen nothing about miracles. The Mishnah is simply saying that you can’t pray for something that has already happened. It is too late to beseech God for mercy because the act is already done.
The Talmud then raises a very specific question. It does not challenge the general principle about praying for the past, nor does it being up anything about miracles. The Talmud’s question is simply that praying for the sex of your inborn child cannot be an example of this forbidden prayer, since Leah did it. The simplest explanation of this is that the Talmud has no reason to assume that the sex of the child has already been chosen, and Leah was in fact praying for the future.
The Talmud then presents two answers. The first answer retains the assumption in the Mishnah that the sex has already been chosen, and acknowledges that in most cases such a prayer would indeed be inappropriate. In this particular case, though, Leah wasn’t actually praying about the past. She acknowledged that the sex had already been chosen; she was specifically asking for a miracle to change the sex. (The miracle is to change the sex now, not to change the past.) This no longer conflicts with the Mishnah’s rule about praying for the past.
The second answer instead modifies the assumption about the sex having already been chosen. It maintains that in some cases the sex has in fact not been chosen yet, and in those cases it is indeed appropriate to pray for the sex.