The official teaching of the Church is that denying Christ even if done falsely is always an intrinsic evil. Which means that it can never be done under any circumstances. The end does not justify the means. The same would go with any other sin in which one is threatened to lose one’s life. This would include stealing, adultery, fornication, sodomy, abortion, murder, etc. The Church has canonized St. Maria Goretti also to guide men and women who are put in such a situation of rape in which the rapist asks them to give consent under threat of death or harm. It is always wrong to do these things under any circumstances. So, it would certainly be a mortal sin if done so with full knowledge and deliberate consent. I do not think Jesus or St. Peter would say that it was justified nor even venially sinful for St. Peter to deny Jesus.
Now, with that said, the Church also teaches that under such grave circumstances some people might not be in a good state of mind to be guilty of mortal sin. It can happen that a person is so tramatized, in a state of shock, emotional breakdown, extreme fear, or in some other psychological state that might diminish the person’s reasoning capacity to make the correct decision. So, in such a case it would be venially sinful. But, this is not always the case, it can happen that one is capable of reason in such a situation and decide to value one’s life over God. Christians are to be a living wittness to God to the world, their very lives are a proof of God’s existence, and therefore one must attempt to save people’s souls by proclaiming God at the point of death. The truth about God is not conditional to the spiritual or moral status of the person requesting it as would be the case with State secrets or an innocent person’s whereabouts. All creatures have an unconditional right to know God and his revelation for the salvation of their souls. Now, if you were to say “No, I do not believe in Christ,” do you have any guarantee that they will not kill you anyway? Not at all, since they might want you to deny Christ so that you may die and go to hell after they kill you. A person that breaks into your house with the intention of killing Christians has no scruples and would most likely sense your hypocrisy and intent on continuing to be Christian and kill you anyway.