The Nintendo Switch is surprisingly sturdy, but this is a common problem: joy-cons that still click (and oh, how I love that click) and snap to the console, but slide off when they shouldn’t (e.g., right in the middle of an online game match).
The cause is a plastic latch that erodes slightly with use (or maybe after it gets jammed on the backplate when you mis-connect it). There is a cheap replacement for that latch that you can order here.
The replacement latch is made of metal (which should have been Nintendo’s original choice), and several videos (like this one) show how to replace it. No soldering is required, just some careful screw removal and disassembly.
With the usual caveats (you do it on your own risk, it voids your warranty, etc.), here is how it went for me.
Nintendo things often use tri-wing screws (in addition to the more common Phillips ones), so the kit comes with one of each screwdriver. It would be handy - if they weren’t horrible. Seriously, do yourself a favour and get a decent tri-wing.
Once you open the joy-con, be careful so you don’t damage the ribbon cables connecting the two halves.
Remove the screws that connect the black board to the back half, and put the later aside.
After you get to the black board, lift the metal blade that holds the latch in its place.
Once the blade is removed, just replace the plastic latch with a metal one from the kit, fitting it over the old one’s spring.
When removing the old latch, be careful so the spring doesn’t fly off. Don’t worry if the spring or any buttons fall out of place - just put them back as you reassemble the controller.
It takes a little time, but it’s worth it: now my joy-con stays firm on its place, only sliding off when I press the button on the back.