"And the LORD spoke suddenly to Moses and to Aaron" (Numbers 12:4). And why did He say to them "suddenly"? Because Aaron and Miriam were still impure, for they had not washed from a seminal emission, while Moses our teacher was pure and clean. This was to make known to Aaron and Miriam that it was on account of this matter that he had separated from his wife: because he did not know when the Holy One, blessed be He, would wish to speak with him, and in order that he might be pure and fit for the divine speech, so that the Holy One, blessed be He, would not refrain from speaking on account of the impurity. For this reason he separated. And because they did not separate, they were found impure when He came to speak with them.
Why God Spoke Suddenly to Moses, Aaron, and Miriam
Midrash Aggadah, Numbers 12:4
ויאמר ה' פתאם אל משה ואל אהרן. ולמה אמר להם פתאום, שאהרן ומרים היו טמאים עדיין שלא נתרחצו משכבת זרע, ומשה רבינו היה טהור ונקי, להודיע לאהרן ומרים שעל דבר זה פירש מן האשה, לפי שלא היה יודע אימתי היה רוצה הקב"ה לדבר עמו, וכדי שיהיה טהור ויהיה ראוי לדבור, שלא ימנע הקב"ה לדבר מלפני הטומאה, לכך פירש, ולפי שהם לא פירשו נמצאו טמאים כשבא לדבר עמם: