לא הגידה אסתר את עמה ואת מולתדה כי מרדכי צוה עליה אשר לא תגיד" ”
Rashi explains the reason Mordechai commanded Esther not to reveal her identity is so that the royal staff would assume that she comes from a low-status social family since those are the goups that have what to hide, and the others would be proud to share. Mordechai was worried if they knew she is a descendant from the family of Shaul Hamelech they would hold onto her, and not be as fast to set her free.
The nearby pasuk tells us that every day Mordechai would visit the courtyard חצר בית הנשים"“ to see how Esther was doing and what is happening to her. Rashi further explains that this was because Mordechai knew that Esther will one day save the Jewish people and therefore he wanted to know what is happening to her. If Mordechai already knew that she will one day save Klal Yisroel why did he command her not to reveal her lineage and by that hope that she will be sent away, this very action might forfeit the possibility of saving Klal Yisroel?
The great Gaon R’ Yechiel Mechel Feinstein explains: Even though Mordechai knew the salvation was to come through Esther, the halacha is that it was forbidden for Esther to remain at the palace and be taken to the non-Jewish king Achasverosh. It was incumbent on Mordechai to do everything in his power to get her out of there. One is never permitted to transgress Halacha even with a noble calculation that it will eventually bring salvation.
We find this concept in Masechet Brachos (Daf yud) Chizkiyahu Hamelech refrained from marriage since he saw via ruach hakodesh that a rasha will come from him. This path earned him the Navi’s rebuke saying “במדי כבשי דרחמנא למה לך”- why are you meddling in Hashem’s ways. Even more the Navi informed him that he was going to die immediately and also forfeit his portion in the world to come if he does not marry.
This episode seems a bit puzzling. Since he refrained from the Mitzvah of Pirya Verivyah his punishment should be so severe that he looses his portion in the world to come?
Had he refrained from Piyah Verivyah for any random reason his punishment would be for not performing a mitzvat aseh in the Torah. However since he was mevatel the Mitzvah because of what he saw through ruach hakodesh that reflects that he preferred to follow Ruach Hakodesh more than keeping halacha. That is a sin that undermines the foundation of Yiddishkeit and therefore he was punished so severely by potentially losing his portion in the world to come.