“A nd the daughters of Tzelafchad drew near…” (Bamidbar 27:1)

The Midrash in Yalkut Shimoni tells us that a person who’s a tzaddik in a generation of wicked people merits the reward of the whole generation. We find this concept by Noach and Avraham.

So too Bnos Tzelafchad approached Moshe at a time when Bnei Yisrael were saying “Let’s appoint a head and return to Mitzrayim.”

Moshe said to them “Bnei Yisrael are requesting to return to Mitzrayim and you’re requesting a portion of Eretz Yisrael?” Therefore they take the reward of the whole nation. (Rav Mordechai Ilan Mikdash Mordechai)