Примерно так можно исправить код. Собрать все parents, пройтись по ним forEach и передавать в on(parent)
document.addEventListener( "DOMContentLoaded" , function() {
const on = (parent, event, selector, fn) => parent.addEventListener(event, ({target}) => {
if(target = target.closest(selector)) fn(target)
});
const parents = document.querySelectorAll(".section-gallery-wrapper.flexbox");
parents.forEach( parent => {
//const on = (parent, event, selector, fn) => parent.addEventListener(event, ({target}) => {
// if(target = target.closest(selector)) fn(target)
//});
//const parent = document.querySelector(".section-gallery-wrapper.flexbox");
const children = parent.children;
let index = [...parent.children].indexOf(parent.querySelector("._active"));
const show = ({dataset : {up}}) => {
children[index].classList.remove("_active");
index = (Number(up) + index + children.length) % children.length;
children[index].classList.add("_active");
};
//on(document, "click", "[data-up]", show);
on(parent, "click", "[data-up]", show);
});
});