No idea how to do that. I can't even find documentation on how to write SWC plugins in Rust. In vanilla JS you could do something like this to create a new style and add it to your div:
// create style element
let style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = '.red { background: #f00; }';
document.getElementsByTagName('head')[0].appendChild(style);
// assign it to the div with the `background="red"` attribute
let div = document.querySelector('[background="red"]');
div.classList.add("red");
But I have no idea how the SWC API works and if you can do the same. There is the web-sys crate that exposes the browser APIs to your Rust code. It contains the functions and types I used in the above JS snippet.
Then again you want to write a plugin for Next.js so you probably want to add the class during server side rendering and not on the client side. So what I just wrote is of no interest to you at all...