What I do find is that when it comes to climbing small hills I tend to catch them up !
What's probably happening here is that because you are both going more slowly the time gap between you results in a smaller distance on the road.
Let's say you are both going up a hill at 10kph and the person who has overtaken you is 10 seconds ahead of you. That 10s will be about 28m on the road.
But if you are on the flat and you are going at 30kmh and the person is 10s ahead of you that 10s will be over 80m on the road.
So when you both slow down to go up a hill the physical gap between you closes, but the time gap is still there.
There's also the possibility that you may have decided to chase after them when overtaken. So they pass you at their cruise speed and maintain that speed. You go flat out to try to catch up, come to a hill where both speeds drop and you will get closer.
I consider myself a bit of an expert at being overtaken as it happens a lot
. It can be useful as you can use them as a pacer to up your pace for a while if that's what you want to do - give them 50m or so and then try to keep them in sight for as long as possible. I also find it important to know when a whole line of riders have passed. When I see what I think is the back marker I normally ask "are you the last"?