The issue you're describing is one of the most challenging and important aspects of learning to play the Piano: the differentiation of the hands.
At the root, this is a brain/coordination issue and it's directly related to the type and amount (think: throughput) of coordination the brain has to 'process.' Consider how difficult most people find it to do the old "pat your head while you rub your tummy" (and then SWAP the two actions) routine. I still find that coordination brain-teaser hard to do!
It's true that greater playing experience over time helps generally, but most of us need something more specific and concrete than that. What I usually recommend is to tackle a challenging hand-differentiation task by breaking it down into smaller, intermediate steps first, and then combining those smaller steps slowly and systematically until the larger, composite hand-differentiation skill is built up and achieved. The secret is breaking down the composite task into SMALL ENOUGH sub-tasks and practicing just those first, until the brain can manage them individually.
College music majors typically do exercises in their sight-singing/ear training classes wherein one aspect of musical performance is isolated from all the other aspects—i.e., they perform an intermediate step that easier to achieve. For example, students will perform or transcribe rhythm patterns without any pitch involved. They will also sing or notate arhythmic pitch patterns that are divorced from any sort of meter or regular rhythmic patterning. Leaving out either pitch or rhythm cuts the job down to about half for the brain.
As a Pianist, you already know that you can practice the hands separately, and you can also temporarily make the tempo as slow as you wish during practice in order to consciously sort out the hand (and occasionally foot) maneuvers required for a piece. What I'd suggest here is trimming down the playing of a difficult passage in some piece to INDIVIDUAL hand maneuvers (as necessary), or to PAIRS of Left/Right hand maneuevers, in isolation from the rest of the piece. If necessary, don't even worry about trying to do the rhythm—just the correct SEQUENCE of the hand maneuvers is what matters initially, and not their timing in a rhythmic context.
This is, again, primarily a matter of brain-training of coordination. For example, many Pianists have trouble making a (phrase or other articulative) 'break' with one hand while playing legato (no break) in the other hand. This is because our brains naturally want to MATCH what both hands are doing rather than DIFFERENTIATING them to do separate tasks. Most of us fail to conquer at least some of these coordination difficulties because we overdrive our brain's ability to 'sort it all out' in real time as we try to read and play the music (over and over again). So, again, I suggest: Simplify the task to the point where you can't get it wrong! That way you'll end up practicing complete success rather than just partial success.
For example: If, say, your Right Hand has to lift off a note at the end of a phrase to create the proper phrase break but your Left Hand has to continue playing legato (no lift/no break) you're faced with a 'pat the head but rub the tummy' sort of problem. To let your brain FEEL what the proper hand maneuvers are for that passage so that it can discern them by 'feel' and replicate them later (correctly) when you replay the same passage again next time, you have to be KIND to your brain and simplify the task down to its most basic challenge. For me, this often means: DISCARD THE RHYTHM ENTIRELY! And it also often means: Don't bother playing the entire BEGINNING of the phrase—which consumes some of your brainpower and attention—because the problem occurs at the END of the phrase, where the Right Hand has to lift off the keys to create the phrase break but the Left Hand has to remain down on its key(s).
And so what you do is: (1) Forgetting about rhythm temporarily, play the notes in both hands at that particular spot and then do JUST THIS ONE THING: (2) Lift the Right Hand off its final phrase note and hold it up off the key(s) while the Left Hand stays down on its key(s). Then (3) FREEZE and HOLD that position for a moment so your brain can 'record' the sensation of the proper hand being up while the other hand remains down. Then do the same thing 1-3 more times until you're comfortable with the maneuver. When that maneuver is comfortable, then tack on JUST ONE previous note in either hand so that your brain feels the transition from the previous note to the newly learned maneuver. It's not important yet to play everything in proper rhythm, but only to practice the proper sequence of correct hand maneuvers.
Eventually, tack on the NEXT note in each hand—but only one hand at a time—so that you 'attach' the newly learned maneuver to the notes both immediately preceding and immediately following it. In this way you can gradually 'stitch' the difficult maneuver back into its original musical context and play the music, successfully, in rhythm. Just reinstate the rhythm in small enough increments that you can cope with it on top of the maneuver sequence you've been
been practicing.
The key to everything is: CONSTRUCT INTERMEDIATE STEPS that are small enough that you CAN'T GET IT WRONG, and practice those first. Then 'glue' those steps back together into the larger musical context. Remember that you can temporarily jettison rhythm and dynamics altogether if you need to while you work on the basic 'Right Hand goes UP while Left Hand STAYS DOWN' maneuver. Find the reduced level of complication where your brain CAN sort out everything it has to do correctly and then practice THAT sequence of maneuvers a few times before tacking on more music before/after the troublesome spot.
In the long run you should end up spending LESS practice time learning a piece this way, because you're practicing SUCCESS rather than hit-and-miss-through-brute-repetition. Bottom line: Just BE KIND TO YOUR BRAIN.