Guess I forgot to mention that when I do this, I space the box with shimming as thick as the wire so I can feed from the back. Doesn't meet volume requirements but it does enclose the connection when you don't have enough wire from the original installation and I've never known of a problem doing it this way. In this case with far less than 15A used on the lighting, I don't worry about box volume as much as I do keeping the connection protected.

Best to do it right by code but that doesn't automatically make another method patently unsafe. To truly do this properly you'd have to open the wall and replace the original wire with one appropriate to the new purpose to eliminate all unnecessary splice connections which is good practice, so even though a splice in a proper box meets one standard, it doesn't meet another.

I've seen more than a few similar situations where somebody just wire-nutted and taped that extension. Thinking of the the sink nearby, water splashing, one hand grounded at the sink while reaching for something under that cabinet- it makes my spine shiver

Phil