Here is a simple way to generate your triplets (they're not pairs!):
triplets = @(v) [circshift(v, [0 1]); v; circshift(v, [0 -1])]';
And here is how to get your output:
y = [2 3 1 5 6];
d = [2 1 5 4 3];
triplets = @(v) [circshift(v, [0 1]); v; circshift(v, [0 -1])]';
ytriplets = triplets(y)
dtriplets = triplets(d)
[~, col] = min(dtriplets, [], 2);
out = ytriplets(sub2ind(size(ytriplets), [1:size(ytriplets, 1)]', col))