It occasionally happens that a child is not medically fit to undergo circumcision until several weeks, or perhaps even several months, after birth, such as in the case of a baby born prematurely or a child who suffers from some medical condition, Heaven forbid. If this infant is a firstborn boy, and thus requires a Pidyon Ha’ben, the Pidyon Ha’ben is performed as usual on his thirty-first day, even though he cannot yet be circumcised. This is the ruling of, among others, the Hid"a (Rav Haim Yosef David Azulai, 1724-1806), in his Haim Sha’al (1:31). Hacham Ovadia Yosef, in presenting this ruling (Yabia Omer, vol. 4, Yoreh De’a 25), notes that the Misva of Pidyon Ha’ben serves as a source of merit for the child’s health. The Gemara refers to Pidyon Ha’ben as "Yeshu’a Ha’ben" ("the boy’s salvation"), and thus this Misva can serve as a source of much-needed salvation for this ill child. This is, indeed, the accepted custom.
If it happens that the child becomes fit for circumcision on the 31st day – the same day as his Pidyon Ha’ben – then the Berit should be performed first, followed by the Pidyon Ha’ben. This ruling is mentioned by the Shach (Rav Shabtai Ha’kohen, 1621-1662), in Yoreh De’a (305:12; listen to audio recording for precise citation), where he explains that one first enters the covenant and then assumes Misva obligation. Therefore, the child should, when possible, first undergo Berit Mila before proceeding to the Misva of Pidyon Ha’ben.
In the case of a child who requires incubation after birth, some halachic authorities maintained that an incubator is, essentially, an artificial womb, and thus the child is not considered to have been born until he can live outside an incubator. According to this view, the count of thirty-one days to the Pidyon Ha’ben does not begin until the baby is taken out of the incubator. The consensus of Poskim, however, disagrees, and maintains that a baby is considered born once he exits the womb, and thus the thirty-one-day count until the Pidyon Ha’ben begins at the moment of birth, even if the child needs to spend time in an incubator and cannot survive without incubation. This is the ruling of Rav Yosef Shalom Elyashiv (1910-2012), as cited in Torat Ha’yoledet.
Summary: If a firstborn infant is medically unfit for circumcision until after the time for his Pidyon Ha’ben (his thirty-first day), the Pidyon Ha’ben is nevertheless performed as usual. If the Berit Mila and Pidyon Ha’ben happen to both be performed on the same day, the Berit Mila should be performed before the Pidyon Ha’ben. The count of thirty-one days for a Pidyon Ha’ben begins immediately at birth, even if the infant requires incubation and cannot survive outside an incubator.