How to reduce code in hash created using Database and Params in rails
Not sure if it's what you're looking for, in terms of readability:
data = User.where(id: sample_params.pluck(:user_id))
           .pluck(:department_id, :id).group_by {|u| u.shift }

results = data.map do |department_id, user_ids|
  users = user_ids.flatten.map do |id| 
    email = sample_params.find { |user| user[:user_id] == id }[:email]
    {user_id: id, email: email}
  end
  { department_id: department_id, users: users }
end

About saving memory because of the array, there will be always the queried data to the db in memory, besides this new array you're generating. The garbage collector won't take care of all these until your http request has been finished, so I'm not sure if there's something here you can do to improve the use of space.
If this is the case where there are thousands of users mapped to this json, maybe you should consider to use .find_each, maybe caching data or another approach, but only you know what's the nature of the data you're querying.