In summary, I don't believe that Eloquent supports groupBy (you'll have to write your own query); and you're not grouping all of the columns.
Your query is not modifying the columns to be selected, so laravel will be selecting all of them; and as such something unique like your IDs will be breaking up the groups. You either need to be explicit about what you're selecting to enable the groups, or explicit about how to summarise the other columns.
The examples on the docs all show customised select queries, with the exception of those specifically under the heading 'groupBy / Having', which is probably a failure of the docs.
But note the other examples, such as this one, that applies grouping functions to all selected columns:
$users = DB::table('users')
// count is a grouping function; status is grouped below
->select(DB::raw('count(*) as user_count, status'))
->where('status', '<>', 1)
Is grouping what you really want? Grouping summarises the table, for example by provided totals, or counts, or unique 'names'. If so, you'll need to modify the query manually, like the example above.
If you just want to order them by 'name' (i.e. group them together) then you want the orderBy function. In which case, you'd modify your code as follows:
return Detail::whereIn('id', $array)
Whilst I don't think it matters here, you may wish to consider whether
name is a unique column name between the master and detail tables.