Your code is technically working. The bg-blue-500 class is being merged into the component, but bg-red-500 has higher priority in your css file.
I believe this would best be done with props.
@props(['background' => 'bg-red-500'])
<div {{ $attributes->merge(['class' => 'text-white ' . $background]) }}>
{{ $slot }}
</div>
<x-component background="bg-blue-500">
// some content for the slot
</x-component>