How to generate a new UTexture2D asset from only pixel data?

You can look how epic does it in UCurveLinearColorAtlas.
That one takes a list color curves and creates a texture out of it.

I would not necessarily do it exactly the same way and just reuse the part writing into the texture.