Trek often shoots episodes out of order. For example, TNG episode in which Tasha Yar was killed off (Skin of Evil) was filmed before "Symbiosis" but aired afterwards. Most obvious is TOS episode "The Man Trap" which aired before "Where No Man Has Gone Before."
There are other examples that fit this better.
TNG...
"Unification II" was filmed before the first part due to Nimoy's schedule, and obviously had to be aired second.
DS9...
"THROUGH THE LOOKING GLASS" was filmed smack in the middle of the season 3 two-parter "IMPROBABLE CAUSE"/"THE DIE IS CAST". Obviously, they would have had to air it before or after the two-parter, which they opted for before.
Season 6's "ROCKS AND SHOALS" was filmed after "SONS AND DAUGHTERS", but clearly had to be aired second due to how Martok and Worf picked the crew up from that planet.
VOYAGER...
Season 2's "INVESTIGATIONS" was filmed before "LIFESIGNS", but had to be aired after because of the Michael Jonas arc.
So it is quite possible to film out of order, and has been done. SUPERNATURAL, STARGATE SG-1, BABYLON 5 (The most blatant example being the season 1 finale filmed literally in the middle of the season), and many other shows have done this.