The concept of hiding one's faith in order to protect one's life is found in the Quran and the sunnah. The Quran talks about this in verse 106 of surah Nahl (16) and we also find this in the words of the holy Prophet (s), for example in regards to Ammar, his companion who had to lie about his faith in order to save his life.
This is because human life is precious and we should always protect ourselves from harm, as the Quran say in verse 195 of Surah Baqarah (2).
BUT, in certain circumstances, things which are more important than human life are in danger and in those cases, saving oneself is not correct, because at that point your life is less important. One famous example is what you correctly mentioned: imam Hussein realized that Islam was in danger and it could only be saved if he stood against the corrupt tyrant and resisted against him. It is true that it cost him his life, but that is because more important that his life was the religion of Allah (swt) and the sunnah of the Prophet (s).
So, hiding your faith is a good thing when the situation is such that it won't have any effect on something more important than your life, since at the end of the day faith is something related to the heart (verse 14 of surah hujurat 49). However, when something more important that your life, such as the religion of Allah (swt), is in real danger, than hiding your faith to save your life is Not correct.