Yes they are invalid sometimes- but not because they are done by heretics. If one has valid priesthood with apostolic succession, has proper form and matter for sacrament (for Eucharist you need Bread and Wine, and words of consecration at least explicitly stated) and has proper intent (in Eucharist, to consecrate the Bread and Wine into Body and Blood of Our Lord) and understanding of said sacrament (for example not thinking Eucharist is symbol) then that sacrament is valid. Baptism by Protestants who are trinitarian is valid, Eucharist by Iconoclasts was valid, etc.
Also, while perhaps you could have worded your last post differently, I don’t understand why was it deleted so fast, especially if people are allowed to question authority of past Popes but criticizing this one (not joining in, I respect Pope Francis but I understand some of his quotes are misinterpreted) gets your thread flagged. I’m gonna just say that instead of removing thread people who disagreed could have presented their explanations to you and convinced you about what they believe is true, instead of just being offended.
Even if Pope were heretic, he is still Pope. Pope Honorius was heretic but he did remain Pope- he just did not speak infallibly because if he did, he would not be heretic anymore, but he chose not to. Even under Pope Honorius, sacraments of Church were all valid. However, even heretical Pope should NOT be deposed or criticized while alive, as Pope CAN NOT be judged. Do not judge the Pope my friend, that is contrary to Vatican I Council. If Pope dies and his actions can judged, fine, but don’t do it while Pope lives. Max we can do is identify heresy and not live accordingly to it, and Cardinals are supposed to rebuke Pope and/or issue declaration of faith against said heresy without saying Pope is heretical. That’s it kinda. I said that all for sake of explaining it, I do not believe Pope Francis is heretic myself. I’m just saying that even if he was, not much would change for us. Pray for Pope and if you think he is heretical, pray that God shows you and Pope the truth- both of you.
Peace be with you.