i would assume that it would get ruled a safety. a missed field goal is marked as a turnover on downs at the spot of the kick.
The Bill Belichick did something similar to this a couple years back against the Broncos where they were backed up in their own territory and took a safety they were lined up in a punt formation and they simply snapped the ball out out of bounds.
correction, a missed field goal is spotted where the kick is placed. if the field goal attempt was on 4th down, then obviously it would be a turnover on downs. but even if it wasn’t 4th down, a missed field goal from within your end zone would still be marked a safety…
Since it’s damn near completely unlikely, I doubt there’s actually a rule in place to deal with it.
The other team can return a missed FG that doesn’t go out of the endzone (as if it were a punt, and has famously happened once in each of the last 4 seasons-Ravens, Bears twice, and Chargers this past year), so I could see the refs ruling that it was a punt.