How do nasal and aural passages connect?
The eustachian tube connects the nasopharynx to the middle ear, on each side. The (naso)pharynx is basically the back of the mouth, and the middle ear is a cavity behing the eardum.

https://en.wikipedia.org/wiki/Eustachian_tube

It is normally closed when there is no pressure difference between the middle ear and the nasopharynx, by extension between the middle ear and the air around one. Its function is to avoid a ruptured eardrum that could be caused by such difference in pressure. (This could be the case when ascending a mountain, or diving underwater, where the ambient pressure drops or increase, but not the pressure inside the middle ear)

What you are doing is closing all passages for the air to flow out (mouth and nose closed), yet trying to blow it out : this artificially increase the pressure and opens the tubes. While it is usually a passage for air, if there is a fluid buildup it could flow through it too.

Whether it is safe is a more of a medical question, which would be better suited for your physician.