Almost certainly a mechanical problem. Headphone jack insertion into the
socket physically moves a metal contact which diverts the output from
speaker to headphones (i.e. an electrical circuit switch).
If the jack is physically inserted "in-line (at 180 degrees) no problem.
But, folk tend to push the jack in at a slight angle, relying on the socket
to line it up. Over time, this angular pressure can distort the internal
metal connector to the point where it no longer makes contact - no switch,
no headphones, speakers remain connected (the default connection).
It's a probem which has existed since steam radio ! Replacement connector,
a few cents. Labour cost on a laptop (assuming it is a "replaceable"
connector, not welded/integral to the motherboard) ??? big bucks!!
Of course it COULD be something totally different, but as the speakers
remain in circuit, doubtful.