Today I was walking with my colleagues to a restaurant, but on the way I met a friend, whom I wanted to have a small chat with. I wanted to ask my colleagues to go away and then I would catch up with them on the way later, but I was stuck - I didn't know how to tell them this request without looking rude.
You could say, "I need a few moments to catch up with my long-lost friend; please, everyone, go on ahead to the restaurant, and I will meet up with you there shortly."
There are probably a million ways to express this, and it's much easier of course, to think it through with time and space, and much harder to express everything in a polite and effective way in the moment.
A few notes:
I prefer "suggesting" to the group that they go on ahead, in the form of a statement/command, rather than asking them "will you please go on ahead?" in the form of a question. Either one can be done in a polite way. You can use whichever one feels more natural for your personality.
You could also give them a reason why they should, such as "I don't want to delay anyone from getting their food; you all look so hungry! Please, go on ahead and get your orders in." You could even ask them to order for you. The risk with all this is that one or more of your colleagues might say, "Oh, we don't mind waiting a bit longer to eat, it's no problem", and then you would have to make a clearer statement that you WANT them to go ahead so you can have a few moments to catch up with your friend. If this happened, you would come off looking manipulative, rather than polite.
I think part of the challenge is that you are torn between your duty to your colleagues and your desire to visit with your friend. It is indeed possible your colleagues may be less than totally pleased that you are "ditching" them to visit with this person they don't know, especially if there was a discussion agenda for the restaurant visit. Ultimately, it is up to you to give yourself permission to possibly mildly displease a couple colleagues in the moment, and make it up to them later.
It is not enough to only be polite in words; actions matter. Part of how your colleagues will view your politeness is whether or not you do catch up with them shortly at the restaurant. Polite words can only accomplish a limited amount; your colleagues and friend will judge you more on your actions. Did you spend a few quality minutes with your friend, get updated contact information, and make plans for later, and then move extra fast to catch up with your colleagues quickly at the restaurant, so that they hardly noticed your absence? That will matter more than the words.