How to manage arrays from custom functions stored in functions.php?

A callback for an action doesn’t return anything, because that return value is never passed through by WordPress.

Use a filter instead:

add_filter( 'listofnames', 'SomeNames' );

function SomeNames() {

    $names=array( "john","edgar","miles");
    return $names;
}

And in your template you call it like this:

$names = apply_filters( 'listofnames', [] );

foreach ( $names a $name ) {
    echo $name;
}