this was fixed 200 years ago
Jane Austen deliberately solved this problem in the 1790s while trying to not write epistolary style novels (the most rigid 1st-person style written as a chain of correspondences – basically all novels written in the 1700s).
Austen couldn't relate her complicated plots only through the 3rd-person limited POV of her protagonists, but she didn't want to shift to other full-POVs since the stories are about the naive MC misunderstanding other character's motives or being directly lied to.
She invented a technique where the limited POV narrator could undermine Regency social etiquette by stating another character's inner voice embedded within their actions and dialog – with Jane that tends to be biting sarcasm since she's most often revealing an ironic hypocrisy, or sharing a totally unexpected 'hot-take' behind a cool facade.
Goethe also, around the same time, although I suspect he migrated the technique from stage actors who could interject quick comedic asides without breaking the scene's pacing. The audience understood which lines were being said to other characters, and which were being said aloud to no one in particular as an internal thought (as opposed to Shakespeare needing to stop the play for a character to monologue a full soliloquy).
There are earlier examples, but these two novelists made it a whole style and influenced the next 2 centuries of authors.
Free Indirect Speech
it's called Free Indirect Speech (also: Free Indirect Discourse). There's a lot written about it, but probably makes the most sense in context where we can see how the POV is being subverted.
In simplest terms, it's a 3rd-person character's thoughts or opinion stated as objective fact by the narrator when it's clearly just that character's thoughts or opinion.
Pride and Prejudice's famous opening sentence is a perfect example:
It is a truth universally acknowledged, that a single man in possession of a good fortune, must be in want of a wife.
This is NOT a universally acknowledged truth – it's actually a self-serving justification for Mrs Bennet to try to marry off her daughters to rich men. Austen goes hard with her opening line 'universally acknowledged truth' because that's how Mrs Bennet thinks: there will be no compromise. She is committed to this cause and those rich men will thank her later.
The reader is sophisticated enough to understand the context, and that not everything written by the narrator is 'true' even within the story.
Austen could have written 'Mrs Bennet thought to herself', but it isn't as funny and it undermines how committed Mrs Bennet is to the goal – this isn't just an opinion, it's her dogma! Austen doesn't even need say whose belief this is because within a few paragraphs it becomes obvious, and it sets up the real conflict that Mrs Bennet's non-golddigging daughter Lizzie is an odd-ball in this world.
Wiki uses a quote to explain it:
"the illusion by which third-person narrative comes to express...the
intimate subjectivity of fictional characters."
In practice it has more to do with writer confidence, and removing the unnecessary parts.
"--- ... ---," she said to herself.
"blah, blah, blah...," he admonished himself
"I must pay that bill," he thought to himself.
--- ... ---.
blah, blah, blah...,
I must pay that bill.
No quotation marks because nothing was actually spoken or quoted.
No 'he thought to himself' attribution because who should be obvious from the context. The bill is not thinking about itself. The desk is not thinking about bills.... There's only one character in the scene who's worried about money right now.
The reader can easily figure out who these ideas are from by the context (why your examples out of context don't mean anything when 'fixed').
The narrative voice becomes immediate, more intimate, and emotionally transparent – not 'filtered' through the distance of someone else's head.