Accessible is a somewhat relative concept. You need to fully remove a recessed fixture from a ceiling to access the connections. This is a bit more difficult than pulling a switch to get at the wires, or even dropping a canopy style fixture, but it does meet the criteria of accessible.
But one of the main rationales for the rule seems to be to ensure a troubleshooter knows where all the connection are, that none are truly buried in the walls where they can't be found.
I don't know if the code has considered your solution, but it sounds like the box you are suggesting is buried, even though it is attached to the recessed fixture. In a sense, you are modifying the fixture in a way not contemplated by the manufacturer. But it might pass muster with some inspectors since it sounds like the junction would be accessible if you removed the can.
There is another way that might suit. The code now allows for certain in-wall splices that can be buried, such as these.
![nm splice](https://i.stack.imgur.com/LdbME.jpg)
The old wire is inserted into one section of the device, clamped, and screwed in. A new wire is inserted into the other. The halves then snap together and the resultant splice can be buried in a ceiling or wall. If feasible, the completed clamp should be attached to a framing member, but I don't think the code requires it if the wire is left in an unaccessible area.
You could attach this splice to your old wire and run a short extension to your can.
Images and links are illustrative only, not an endorsement of goods or sources.
Why not use a standard round junction box? They come in several widths and depths, for example
![round ceiling box](https://i.stack.imgur.com/bZcaj.jpg)
If the space is very shallow, there are round pancake boxes as well
![pancake box](https://i.stack.imgur.com/R8J3Q.jpg)
Two safety issues:
- It is imperative that a fixture be solidly mounted, so, if it attaches to the box itself, the box must be attached to framing members or an adequate brace.
- Small round boxes have limited space, so you must be careful about overfilling them with wires and attachment devices. If there is a single cable with two or three wires, you will usually be okay, but pancakes generally cannot handle several cables.
SUPPLEMENT: As to the question about a square box in a round hole, NEC Section 314.21 says
Repairing Noncombustible Surfaces. Noncombustible surfaces that are broken or incomplete around boxes employing a flush type cover or faceplate shall be repaired so that there will be no gaps or open spaces greater than 3mm (1/8 in.) at the edge of the box.
Section 314.19 also says that flush fixtures have to be have to be completely enclosed at back and sides, so gaps around a box behind the fixture would probably be considered to violate that as well.
That said, it is routine to apply spackle and other noncombustible fillers around junction boxes that have gaps where they meet the wall. But it is critical to ensure that whatever box is used, it is securely mounted to underlying structure.
Finally, cites are to NEC which may or may not be applicable in your jurisdiction, but is generally viewed in North America as standard practice.
Images and links are for illustration only, not an endorsement of
goods or sources.
Best Answer
It probably has wings with framing nails in them, like this:
You can either try sliding a saw through the gap outside the box and cutting the wings off, or you can cut up and remove the box a piece at a time. That's more difficult with plastic than with fiber, so be prepared for a battle. A rotary tool with a spiral cutter would work well.
If you're patching the drywall anyway, just put a block of wood in the box and drive it upward with a hammer.