How do I seal an electrical box for a ceiling fan?
I believe that insulation falling in is less of a fire hazard than air escaping through the holes during a fire.  The intent is to prevent air from flowing out into the attic space during a fire, which would create a chimney effect and continue to feed the fire oxygen.
But good news, you can achieve both with the same approach.
You want to use a fire-rated expanding foam or caulk. In the gaps within and around a ceiling box, I’d use the intumescent style of either which will expand further when exposed to heat.
Be sure to clean out any foam or caulk that works its way into the electrical box. From a code perspective, it is important to keep the volume of the box the same.
While using electrical tape to seal the holes in an electrical box is likely better than nothing, I don't suspect it will survive the heat of a fire for very long given that it is not &quot;attached&quot; to anything over the void of the hole.  An intumescent caulk or foam will provide a much more durable blockage to prevent not only insulation from falling in, but from air escaping during a fire (which is the bigger concern IMHO).