Fancy merging of PDFs
Eventually, I'm answering my own question, because I finally found a way and I want to leave the complete solution here, in case someone struggles with a similar problem in the future.

The solution involves an amazing program called Poppler available through Homebrew, by brew install poppler. Poppler comes with a variety of pdf management tools, like pdfseparate and pdfunite featured in the script.

Without further ado, here's the script that I wrote:

#!/bin/bash

mkdir ~/Desktop/merging

# number of pdf files containing pages nr 1/2/3/...
n=6

for i in $(seq 1 $n); do
    # ${i}.pdf being a file containing pages nr i
    pdfseparate ~/Desktop/${i}.pdf ~/Desktop/merging/${i}_%d.pdf
done

number_of_pages=$(cd ~/Desktop/merging/; ls | wc -l)
number_of_pages_each=$((number_of_pages/n))

command="pdfunite"

for i in $(seq 1 ${number_of_pages_each}); do
    for j in $(seq 1 $n); do
        command="$command ~/Desktop/merging/${j}_${i}.pdf"
    done
done

command="$command ~/Desktop/output.pdf"

eval $command

# cleanup
rm -rf ~/Desktop/merging