Do you mean you want to remove the box and leave the wiring in the ceiling? I believe it’s code in most places that you have to make wire splices like that accessible and not just shoved behind drywall. So, in your case, code would require you to leave it as-is, with the wires capped behind a blank cover plate.
If you REALLY want it gone, you could get into the attic and pull the wires back into a junction box mounted to a rafter or joist. Then, patch the ceiling drywall.
Probably easier to just cap the wires and add a blank cover.
From what I can tell, you’re right that it is bolted/nailed to the stud.
This is only a temp change, as I’m looking to get up into the ceiling to look for excess water, from a sink overflowing.
The smoke detector drank a bit of water, so I’ll be buying a new one today.