See further detail related to it here. Correspondingly, can you splice wires inside a wall?
Spliced wires are not to be held together with electrician's tape. Electrical wires are never left on their own in the wall cavity or ceiling. Instead, all splices must be contained within a junction box and the individual wires attached with wire nuts.
Also, how do you replace a junction box? How to Remove a Metal Junction Box
Then, can you use a junction box to extend wiring?
If you do need to extend the wires, yes, a junction box would be needed. It must remain accessible. You've pretty well identified your two choices; if you don't want to re-run longer cables, you'll need to splice in some additional cable.
How do you install a junction box?
Mount the Box Separate the circuit wires at the existing splice and loosen the cables as needed to make room for the new junction box. Mount the box to the framing (or other support structure) with screws driven through the factory-made holes in the back or side of the box, as applicable.