You talk with them and explain the situation.
Talk about it, like they are a "team".
Not the older being better or the younger one being better or one being more bossy over the other.
Explain it to them and let them ask anything they want about the arrangement.
Tell them, your hopes about it.
Then, organize the room to accommodate both of them. Fairly.
DO NOT, give the 4 year old, the 'task' of minding his/her younger sibling. This is not his/her responsibility. Or they may resent it.
And yes, 4 year olds, are not all grown up in terms of problem-solving or impulse control or maturity or coping-skills or deductive reasoning. So have a baby monitor in their room... so you can hear them, too.
You will still have to run interference and supervise when needed.
Or, you put their mattresses, on the floor.
Or have a partition or folding screen in between them.
Unless they will push it over.
And if they have different sleep times/nap times.... you will have to toggle that. Because, there is a big difference, developmentally, between a 2 year old and a 4 year old.
And hopefully they get along. But you can't predict that.
Me: I shared a room with my sibling when younger. It was awful. I HATED it. Why? Because my older sibling, was a controlling/fussy/manipulative.... kid. And she only did it, when my parents, weren't looking.
So eventually, I got my own room.
It was needed.
And you need to also factor in, that they will each have their own individual age-related phases.