The waking up is probably habit, teamed with the other habit that when he wakes up slightly he doesn't do what others do and just turn over, wriggle around in bed a bit and go back to sleep. Instead he thinks in his mind that to go back to sleep in the middle of the night he needs to be in your bed.
If you don't mind this, it's not a problem.
If you want to change it, it will need some consistency and tears. Rapid Return would be what I do. It involves being very quick to react. As soon as child is out of the bed you go to them quickly, return to bed, quick kiss, repeat a set mantra "Sleep time now. You must stay in bed, be quiet and go to sleep. Nan night" and immediately turn around and leave. If he gets out of bed again, you repeat exactly the same thing in a calm but expressionless way. Just keep repeating.
The same would work at bedtime, to give added consistency. This time with regards to noise. Don't procrastinate and drag-out bedtime. So cuddles and stories out of bed so that once in bed, the same, quick routine happens. Into bed, quick kiss, "Sleep time now. You must stay in bed, be quiet and go to sleep. Nan night", immediately leave.
You have to leave and be very clear that you will leave the room quickly and child will be going to sleep alone. You have requested in your mantra that the child is quiet. So give it a few minutes then repeat:
"You are not being quiet, I asked you to be quiet and go to sleep". Lie child back down, quick kiss, "Sleep time now. You must stay in bed, be quiet and go to sleep. Nan night", immediately leave.
If child gets out of bed or is making any noise after a few minutes, repeat. Repeat, repeat, repeat, repeat. It may take a long time initially. But a 2 year old is plenty old enough to get this in the end.