A hardcoded array( 12, 31 )
is not the same as array($implode_pages)
.
The earlier is equivalent to
array( 0 => 12, 1 => 31 )
The latter is equivalent to
array( 0 => '12, 31' )
$implode_pages = implode(', ',array_keys($pages, 1));
makes $implode_pages
a string – which is not what you want.
Not only that, it’s an entirely redundant step.
'post__not_in' => array_keys($pages, 1)
should do…