CPT: if more than X images are in post, use pagination

Try

$u = 0;
foreach($photos as $photo) {
$u++;

...

  if( ($params['next'] > 0 && $u == $params['next']) ) {
    $retVal['content'] .= "<!--nextpage-->\n\n";
    $u = 0;
  }

EDIT (explaination)

in the code posted by OP $params['next'] > 0 && $i == $params['next'] assuming $i is incremented every foreach cycle (this is not visible in the code, but it can be intuited) when $i > $params['next'] this not work and the next content is added once.

In my code, using $u = 0 after adding <!--nextpage-->\n\n it should work because $u is incremented again by foreach so my code if( $params['next'] > 0 && $u == $params['next'] ) { should works for every multiple of $params[‘next’].