It depends on the individual, but I'm going to talk about my own experience.
Two things to note:
- It's not really true that each hand is doing something different. Both hands are working together to create a piece of music.
- Although at first glance it's "special" to have one hand playing one aspect of a piece while the other hand plays a different aspect -- if you think about it, the challenge is no different to, say, a guitarist singing while playing.
Going back to the first point, it's common to learn the left-hand part on its own, then the right-hand part, then put them together. However when you put them together, it's not really a case of disassociating one hand's job from the other's and setting them off independently.
Let's take as an example the first few bars of the melody section of "Dance of the Sugar Plum Fairy", in a simple arrangement.
I might try out the left hand part then the right hand part -- to work out the fingering -- but to put them together I would not try to set my left hand off playing E, B, E, C, etc. while independently the right hand plays the melody.
Instead I would note that the order of things is:
- LH E
- LH E and RH G
- RH E
- LH E and RH G
- LH C and RH F#
... and so on, a linear sequence of single notes and chords, played by a combination hands.
The difficulty of playing with both hands is seeing the order of events as they're shared between the hands -- does my left hand do something before the next right hand event, or do I play a right hand note first, or am I playing the next combination of notes with both hands at the same time?
Just like learning to read, when you're a beginner, you have to think about every step. I find it useful to try playing with both hands very slowly and with no regard to a consistent tempo -- just get the notes in the right order. With experience, this gets easier, and if you do it a lot, you'll find that you can do it without thinking -- again, just like reading.
Another mode of piano playing is improvising an accompaniment, perhaps by playing some chord rolls you've learned while playing the melody with the right hand. In this case, learning where the beats are in the roll, and therefore where a melody fits around it, is part of learning the roll. Practice is everything.